0

in _form.html.erb file I wrote:

 <%= f.number_field :tov_id %>

and that code produce this html :

<input type="number" value="3" name="price[tov_id]" id="price_tov_id" />

this code:

 <%= select_tag(:tov_id, options_for_select(@tovs,2), :prompt => "select tov" )  %>

make this html

    <select name="tov_id" id="tov_id">
<option value="">select tov</option>
<option value="1">brake pad</option>
    <option selected="selected" value="2" >nut</option>
    <option value="3">bolt</option></select>

as we can see : the second parameter to option_to_select respond to selected option But when I wrote this:

<%= select_tag(:tov_id, options_for_select(@tovs , :tov_id  ), :prompt => "Select tov" )  %>

no any selected appear :(

    <select name="tov_id" id="tov_id"><option value="">Select tov</option><option value="1">brake pad</option>
<option value="2">nut</option>
<option value="3">bolt</option></select>

How can I get the value from :tov_id and put it to options_for_select ?

riabow
  • 1
  • 2
  • I shuld use @price.tov_id instead :tov_id !!!!! – riabow Oct 14 '16 at 15:45
  • Possible duplicate of [How to have a drop down – Blackcoat77 Oct 14 '16 at 18:12

0 Answers0