rails simple_form_for association select text
I am using Rails 3.0, Ruby 1.9.2 and the Plataformatec simple_form gem.
The code below renders a select box with Consumer names. I want it to show a select box with Consumer locations instead. How do I do that?
View code:
<%= simple_form_for @request do |f| %>
<%= f.association :consumer, :collection => Consumer.all, :prompt => "Ch开发者_如何学Coose a location" %>
<%= f.button :submit %>
<% end %>
Model code:
Consumer < ActiveRecord::Base
attr_accessor :name, :location
end
You would do this via label_method
<%= f.association :consumer, :collection => Consumer.all, :prompt => "Choose a location", :label_method=>:location %>
精彩评论