Undefined `merge 'method for: name: Symbol Rails 4.1.x collection_select

I have a form element with:

<%= f.collection_select :race, :id, Race.all, :id, :name, prompt: true %>

This allows you to choose the race of your characters in the text adventure that I create. The goal is to release all available races, select by name and pass the identifier of this race to the pairs.

But when I load the page, I get an undefined method merge 'for: name: Symbol`

I looked through the docs and I think I'm doing it right, but I guess not? what am I doing wrong?

+6
source share
1 answer

f. indicates that you are in a form_for block? This means that the signature of the f.collection_select method f.collection_select different from the simple collection_select . The first parameter is automatically provided by FormBuilder , so if :race is an attribute of a form object, which I assume is a symbol, you just need to:

 <%= f.collection_select :race, Race.all, :id, :name, prompt: true %> 

See the documentation for the FormBuilder # collection_select method.

+19
source

Source: https://habr.com/ru/post/978697/


All Articles