ruby-on-rails - 选择框中的简单表单默认值

标签 ruby-on-rails simple-form

我使用简单的形式,并且我有 :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/

相关文章:

ruby-on-rails - ruby : http POST with nested params not working

ruby-on-rails - 无法在 Ruby on Rails 中创建以 Bootstrap 为主题的脚手架

css - 将样式添加到 simple_form 集合/下拉列表

mysql - 关键字查询最快的数据库设计

ruby-on-rails - Rails 深度插件教程

ruby-on-rails - rails : Blocking an user using routes. rb

ruby-on-rails - 如何使下拉菜单中的每个选项成为与 simple_form 调用关联的链接?

ruby-on-rails - Rails 4关联验证销毁

ruby-on-rails - 更改日期类型中的年份值范围以适应可能的出生年份 Rails、Simple_Form、HTML

javascript - 为一个表单提交操作设置目标_blank