Undefined method 'merge' for "test":String - Rails 3.1
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 %&g开发者_如何转开发t;<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
精彩评论