选择框中的简单表单默认值

时间:2014-06-13 21:05:01

标签: ruby-on-rails simple-form

我使用简单的表单,我有:selected => 0表示默认情况下select的值为0。但这不起作用,选择框是空白的,我需要手动选择“0”选项......顺便说一句,我是一个模态。有什么想法吗?

  <%= f.input :price_type, label: "¿Conoces el precio?", collection: ["0","1","2"], :selected => 0 , id: "tag_price_type", html_input: "required", input_html: {class: 'ipt'} %>

2 个答案:

答案 0 :(得分:4)

尝试匹配集合和选择之间的对象类型。所以:

<%= f.input :price_type, label: "¿Conoces el precio?", collection: [0,1,2], selected: 0 , id: "tag_price_type", html_input: "required", input_html: {class: 'ipt'} %>

<%= f.input :price_type, label: "¿Conoces el precio?", collection: ['0','1','2'], selected: '0' , id: "tag_price_type", html_input: "required", input_html: {class: 'ipt'} %>

答案 1 :(得分:-1)

您必须使用引号,请参阅:How do I set the default selected item in a Rails drop-down menu?

所以你应该有::selected =&gt; &#34; 0&#34;

相关问题