Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby on rails: Select options menu with default value attribute

I need to produce a select menu with a Default value on the list of <options> . Here is how I need it looks like.

<select name="menu[parent_id]" id="menu_parent_id">
 <option value="0">==None==</option>
 <option value="34">TEST</option>
</select>

Currently I use this select helper in my form

   <%= f.select(:parent_id, @parent_menus.collect {|p| [ p.name, p.id ] }, {:include_blank => '==None=='})%>

the above code produce this; (value="")

<select name="menu[parent_id]" id="menu_parent_id">
 <option value="">==None==</option>
 <option value="34">TEST</option>
</select>

Does anyone here can show me a way to add value="0" to the options list?

like image 658
randika Avatar asked May 05 '10 09:05

randika


1 Answers

<%= f.select(:parent_id, [["==None==", 0]] + @parent_menus.collect {|p| [ p.name, p.id ] }) %>
like image 149
Simone Carletti Avatar answered Sep 18 '22 12:09

Simone Carletti