rich
December 22, 2006, 4:17pm
1
I might have asked this before, but I don’t think I got a reply.
I’m using this code to create a drop-down menu of ‘cuisines’:
<%= select_tag “cuisine_id”,
options_from_collection_for_select(@cuisines , ‘id’, ‘name’) %>
My question is, how can I add an “All Cuisines” option to the start of
this menu, with a nil value? Or is there someway that lets you add a
similar option? It’s a common thing to have in a drop-down menu so I’m
sure it’s been discussed somewhere.
I’m guessing I’d probably have to code it more explicitly. Thanks!
rich
December 23, 2006, 11:11pm
2
Since options_from_collection_for_select returns a string of normal
tags, you should be able to just append it to your own
tag:
<%= select_tag “cuisine_id”,
“All Cuisines” +
options_from_collection_for_select(@cuisines , ‘id’, ‘name’) %>
Or make a helper that does this for you.
Justin
rich
December 27, 2006, 11:17pm
3
blaix wrote:
Since options_from_collection_for_select returns a string of normal
tags, you should be able to just append it to your own
tag:
<%= select_tag “cuisine_id”,
“All Cuisines” +
options_from_collection_for_select(@cuisines , ‘id’, ‘name’) %>
Or make a helper that does this for you.
Justin
Thanks this works perfectly!
rich
December 28, 2006, 6:07am
4
Rich,
Does this code still work if you have a form validation error? Where
are you declaring the @cuisines object?
rich
December 28, 2006, 6:51am
5
The option way works, but I do it this way as well for a list of
countries
where I want USA to appear first…
@usa = Country.find(:first, :conditions => [“name = ?”, usa_name])
@countries = Country.find(:all,
:conditions => [‘country_code IS NOT NULL
AND
name <> ?’, usa_name],
:order => ‘name ASC’)
@countries.insert (0, @usa )
You might want to do a similar thing in your controller, who knows.
On 12/27/06, JL Smith [email protected] wrote:
Rich,
Does this code still work if you have a form validation error? Where
are you declaring the @cuisines object?
–
seth at subimage interactive
http://dev.subimage.com/projects/substruct