【问题标题】:Simple form input type简单的表单输入类型
【发布时间】:2013-09-30 08:12:49
【问题描述】:

我正在使用 simple-form gem 来呈现我的表单。我正在尝试将输入字段类型设置为“数字”。此代码不起作用:

f.input :amount, input_html: { type: 'number' }

设置的正确方法是什么?

【问题讨论】:

    标签: ruby-on-rails html simple-form


    【解决方案1】:

    以下应该可以工作

    f.input :amount, input_html: { type: 'number' }
    

    更简洁的方法是:

    f.input :amount, as: :numeric
    

    希望对你有帮助!

    【讨论】:

    • 这应该是'as::numeric'
    • 我将答案更新为正确(并使用当代 Ruby 哈希语法)。奇怪的是,OP 问题中的代码f.input :amount, input_html: { type: 'number' } 确实有效。不过我个人更喜欢as: :numeric 版本。
    【解决方案2】:

    最简单的方法:

    f.input :whatever, as: :numeric
    

    【讨论】:

      【解决方案3】:

      试试:

      f.input :amount, as: :integer
      

      【讨论】:

        猜你喜欢
        • 2017-09-04
        • 1970-01-01
        • 1970-01-01
        • 2015-09-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-05-08
        相关资源
        最近更新 更多