开发者

cant convert symbol to integer using select_tag

开发者 https://www.devze.com 2023-02-08 19:49 出处:网络
could anyone please tell me what is wrong this this code?开发者_如何转开发 I get a can\'t convert Symbol into Integer

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 :)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号