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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With