cant convert symbol to integer using select_tag
could anyone please tell me what is wrong this this code?开发者_如何转开发
I get a can't convert Symbol into Integer Extracted source (around line #5):
3: <% form_for @song_request do |f| %>
4: <p>Please select the event you are attending:</p>
5: <%= select_tag('song_requests', 'event_id', Event.all.collect {|e| [e.name, e.id ] } ) %>
6: <% end %>
collection_select
will do what you're wanting and reads much better:
<%= f.collection_select :event_id, Event.all, :id, :name %>
Ok I agree with idlefingers that you have to go with collection_select method here (although it must read <%= f.collection_select :event_id, Event.all, :name, :id %>
) but you also have the alternative to go with the select method as
<%= f.select :event_id, options_for_select(Event.all.collect{|e| [e.name,e.id]})
You have to note that it is a best practice to not use *_tag methods when you wrapping the form fields in a form_for
block. That is the whole point of using form_for
you are carrying the object @song_request
in the iterator :)
精彩评论