Reputation: 3422
I am trying to pass to my select_tag both fixed values and loop values. I can perfectly write something like :
<%= select_tag "", options_for_select(session[:user_hotel_list].collect{ |hotel| [hotel["name"], hotel["id"]] }) %>
Here hotel["name"]
will be the displayed value and hotel["id"]
the "real value" of the field.
But if I try to add extra fixed values to my options_for_select I dont get the desired output. Let's say I want to add a select with "all hotels" with a value of "all". I would try something like that :
<%= select_tag "", options_for_select([["all hotels", "all"], session[:user_hotel_list].collect{ |hotel| [hotel["name"], hotel["id"]] }]) %>
But here I would get an array as output for the collection...
How can I correctly add extra fixed data to an options_for_select with a collection in rails ?
EDIT
For example this code :
<%= select_tag "dash_select", options_for_select( [["all hotels", "all"], ["other", "value"]] << session[:user_hotel_list].collect{ |hotel| [hotel["name"], hotel["id"]] }) %>
and obviously ["plaze", 31] isnt good !
Upvotes: 0
Views: 300
Reputation: 1723
Do you really need to add multiple items? Or is your example with just "All hotels" sufficient. Because in that case you could just do:
<%= select_tag "", options_for_select(...), { include_blank: "all hotels" } %>
Upvotes: 1