I have a collection_select:
<%= form_for(@feedback) do |f| %>
<div class="field">
<%= f.label :poster_id %><br />
<%= f.collection_select :feedback, :poster_id, @users, :id, @user.username, :prompt => "Select your username" %><br />
<%= f.number_field :poster_id %>
</div>
<% end %>
This is the error message:
ActionView::Template::Error (undefined method `merge' for "test":String):
15:
16: <div class="field">
17: <%= f.label :poster_id %><br />
18: <%= f.collection_select :feedback, :poster_id, @users, :id, @user.username %><br />
19: <%= f.number_field :poster_id %>
20: </div>
21: <div class="field">
app/views/feedbacks/_form.html.erb:18:in `block in _app_views_feedbacks__form_html_erb__3181571289116259961_2154876620'
app/views/feedbacks/_form.html.erb:3:in `_app_views_feedbacks__form_html_erb__3181571289116259961_2154876620'
"test" is the username that was returned by @user.username
.
How do I fix that?
the signature for collection_select is:
def collection_select method, collection, value_method, text_method, options = {}, html_options = {}
i'm not sure what you're trying to do, maybe this is what you want:
<%= f.collection_select :poster_id, @users, :id, :username, :prompt => "Select your username" %><br />
I had to think of the inputs this way to get it to make sense in my head...
collection_select ‘model field’, ‘collection of options in the dropdown menu’, ‘model field for values’, ‘model field to show in the menu’
This helped me understand
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