I’m using Rails 4.2.3. I have the following helper method for getting US states …
def us_states
us_country = Country.find_by_iso('US')
State.where(country_id: us_country.id)
end
Then in my view I have
<%= addr.select :state, us_states.collect {|s| [ s.name, s.id ] }, {prompt: 'Select State'}, class: "selectField selectMenu form-control" %>
However, what is being rendered in my view is
<select name="my_object[address][state]" id="my_object_address_state"><option value="">Select State</option>
<option value="#<State:0x007f9f562fe368>">#<State:0x007f9f562fe368></option>
…
<option value="#<State:0x007f9f563124a8>">#<State:0x007f9f563124a8></option></select>
How do I make the actual names and IDs of the states appear in my select tag?
You are missing options_for_select, Change your select with this:
<%= addr.select :state, options_for_select(us_states.collect{|s| [ s.name, s.id ]}), {prompt: 'Select State'}, class: "selectField selectMenu form-control" %>