我使用简单的形式,并且我有 :selected => 0,因此默认情况下,选择的集合中的值为 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'} %>
最佳答案
尝试匹配集合和选择之间的对象类型。所以要么:
<%= 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'} %>
关于ruby-on-rails - 选择框中的简单表单默认值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24213799/