Here is my code snippet that works exactly as intended:
<%= f.select(:other_model_id,
options_from_collection_for_select(
OtherModel.all,
:id,
:full_name,
{ :selected => @this_model.other_model_id} )) %>
But for some reason, this doesn’t work:
<%= f.collection_select :this_model, :other_model_id,
OtherModel.all, :id, :full_name %>
There error I get is:
undefined method `merge’ for :full_name:Symbol
Any suggestions? The fact that :full_name works properly with the working code leads me to believe I screwed up the syntax in the simplified collection_select code and that the problem is not elsewhere.
I think you’re mixing up two different
collection_selectmethods. You’re calling theFormBuilder#collection_selectusing theFormOptionsHelper#collection_selectarguments. Maybe you want this:Or perhaps this:
You end up trying to put
:full_namein theoptionsargument but that’s supposed to be a Hash, that’s where the complaint about “nomergemethod” comes from.