Rails:为禁用的select帮助程序提供默认值

时间:2016-06-03 09:37:03

标签: ruby-on-rails select default

我有一个选择助手,如下所示,我已禁用它,并希望给予" 1"作为默认值,但无法找到?

<%= f.select :fuel_incl, [[t('shared.incl'),'1'],[t('shared.notInc'),'0']], {}, {class: "Select-control u-sizeFull fuel_incl", :disabled => true} %>

它被禁用,所以它应该选择1作为默认值。

修改

我看到它可以在控制台上运行;

<select class="Select-control u-sizeFull fuel_incl" disabled="disabled" name="boat[fuel_incl]" id="boat_fuel_incl">
<option selected="selected" value="1">Included</option>
<option value="0">Not Included</option></select>

但它不发送为params,当我取出禁用true并选择值发送表单时,它可以工作..

EDIT2

无论如何,我只通过给出一个选择值来解决它;

<%= f.select :fuel_incl, 
             [[t('shared.incl'),'1']], 
             { selected: '1' }, 
             { class: "Select-control u-sizeFull fuel_incl" } %>

1 个答案:

答案 0 :(得分:1)

添加selected选项:

<%= f.select :fuel_incl, 
             [[t('shared.incl'),'1'],[t('shared.notInc'),'0']], 
             { selected: '1' }, 
             { class: "Select-control u-sizeFull fuel_incl", disabled: true } %>