Search code examples
ruby-on-railsform-helpers

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?


Solution

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