jason
February 1, 2007, 9:33pm
1
What am I doing wrong here? I’m trying to create a select box with a
normal id/value setup.
Here’s my code:
<% form_tag ‘/list’ %>
<%= collection_select( :route_id, @routes, :id, :name, {}, {} ) %>
<%= end_form_tag %>
Here’s the NoMethodError exception I’m getting:
undefined method `inject’ for Symbol
Extracted source (around line #15 ):
12:
13: <% form_tag ‘/list’ %>
14:
15: <%= collection_select( :route_id, @routes , :id, :name, {}, {} )
%>
16:
17: <%= end_form_tag %>
18:
What am I doing wrong?
Thanks!
jason
February 1, 2007, 9:42pm
2
<%= collection_select( :route_id, @routes , :id, :name, {}, {} ) %>
You may be using the wrong tag here. collection_select is for model
fields so expects:
collection_select(object, attribute, collection, value_method,
text_method)
You probably want something like this:
<%= select_tag(‘route_id’,
options_from_collection_for_select(@routes , :id, :name)) %>
Steve
jason
February 2, 2007, 1:15am
3
I’ve tried that and it does work, so I appreciate your help.
How can I add an onchange event to this select box now?
Thanks,
Jason
jason
May 11, 2007, 12:36pm
4
jason
February 2, 2007, 1:27am
5
Actually, I figured that out, but how can I insert a default value, like
‘Please select an option…’ to the select box?