Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/55.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 使用Simple_表单在:集合中显示数据库中特定字段的信息_Ruby On Rails_Ruby - Fatal编程技术网

Ruby on rails 使用Simple_表单在:集合中显示数据库中特定字段的信息

Ruby on rails 使用Simple_表单在:集合中显示数据库中特定字段的信息,ruby-on-rails,ruby,Ruby On Rails,Ruby,在数据库中,clients表包含名称、电话和其他数据。但是,如果我创建了一个与Simple_form的关联,它会在选项中显示名称,有没有一种方法可以代替在表单的选项中显示名称来显示手机 下面是我当前使用的显示名称的代码 <%= f.association :client, :required => false, :prompt => "Eliga Cliente", :label => "Clients", :collection => Client.wher

在数据库中,clients表包含名称、电话和其他数据。但是,如果我创建了一个与Simple_form的关联,它会在选项中显示名称,有没有一种方法可以代替在表单的选项中显示名称来显示手机

下面是我当前使用的显示名称的代码

<%= f.association :client, :required => false, :prompt => "Eliga Cliente", 
  :label => "Clients", :collection => Client.where(:status => true).order("id ASC") %>

您可以传递label_方法参数并将其设置为适当的属性

<%= f.association :client, :required => false, :prompt => "Eliga Cliente", 
:label => "Clients", :collection => Client.where(:status => true).order("id ASC"),
:label_method => :phone %>