Ruby on rails: Select options menu with default value attribute

randika picture randika · May 5, 2010 · Viewed 10.8k times · Source

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?

Answer

Simone Carletti picture Simone Carletti · May 5, 2010
<%= f.select(:parent_id, [["==None==", 0]] + @parent_menus.collect {|p| [ p.name, p.id ] }) %>