[英]rails simple_form_for association select text
I am using Rails 3.0, Ruby 1.9.2 and the Plataformatec simple_form gem.我正在使用 Rails 3.0、Ruby 1.9.2 和 Plataformatec simple_form gem。
The code below renders a select box with Consumer names.下面的代码呈现一个带有消费者名称的 select 框。 I want it to show a select box with Consumer locations instead.
我希望它显示一个带有消费者位置的 select 盒子。 How do I do that?
我怎么做?
View code:查看代码:
<%= simple_form_for @request do |f| %>
<%= f.association :consumer, :collection => Consumer.all, :prompt => "Choose a location" %>
<%= f.button :submit %>
<% end %>
Model code: Model 代码:
Consumer < ActiveRecord::Base
attr_accessor :name, :location
end
You would do this via label_method你可以通过 label_method 做到这一点
<%= f.association :consumer, :collection => Consumer.all, :prompt => "Choose a location", :label_method=>:location %>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.