如何在选项ROR中设置“选中”

时间:2016-10-12 11:24:55

标签: ruby-on-rails

我写的_form.html.erb文件中的

 <%= f.number_field :tov_id %>

并且该代码生成了这个html:

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

此代码:

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

制作此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>

我们可以看到:option_to_select的第二个参数响应所选的选项 但是当我写这篇文章时:

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

没有任何选择出现:(

    <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>

如何从以下值获取值:tov_id并将其放入options_for_select?

0 个答案:

没有答案