Reputation: 1054
I have a form element with:
<%= f.collection_select :race, :id, Race.all, :id, :name, prompt: true %>
This allows you to select your characters race in a text adventure I am creating. The goal is to have a drop down with all available races, select by name and have the params pass the id of that race back.
But when I load the page I get undefined method 'merge' for :name:Symbol
.
I looked up the docs and I think I am doing it right, but I guess not? what am i doing wrong?
Upvotes: 16
Views: 10883
Reputation: 4879
The f.
indicates you are in a form_for
block? Which means the method signature of f.collection_select
is different to just plain collection_select
. The first parameter is automatically supplied by the FormBuilder
, so if the :race
is an attribute of the form object, which I assume is a Character, you just need:
<%= f.collection_select :race, Race.all, :id, :name, prompt: true %>
See the documentation for the FormBuilder#collection_select method.
Upvotes: 34