【问题标题】:Having troubles getting my rails form to work无法让我的导轨形式正常工作
【发布时间】:2015-09-16 10:17:05
【问题描述】:

我已经尝试了好几个小时来让我的 rails 表单工作,但我做不到。它不断抛出的错误说:

ArgumentError 在 / 参数数量错误(1..2 为 3)

并且它说发生此错误的代码行位于 f.input 行。有什么想法吗?

.select-width
 = f.label :country 
 = f.input :country, :select, :as => :fancy_select, collection: ['South Africa', 'Nigeria', 'Zimbabwe', 'Mali', 'Namibia'], hint: 'Lorem ipsum hint'

【问题讨论】:

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


    【解决方案1】:

    simple_form 中,input 只需要两个参数。

    1. 为字段名
    2. 选项哈希(此参数可选)

    因此,您可以使用以下代码。它会正常工作。

    .select-width
      = f.label :country
      = f.input :country, as: :fancy_select, collection: ['South Africa', 'Nigeria', 'Zimbabwe', 'Mali', 'Namibia'], hint: 'Lorem ipsum hint'
    

    【讨论】:

      【解决方案2】:

      我假设你使用的是simple_form

      我想它会起作用的:

      = f.input :country, collection: ['South Africa', 'Nigeria', 'Zimbabwe', 'Mali', 'Namibia'], as: :fancy_select
      

      你可以查看documentation他们是如何定义select标签的。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-04-10
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-12-10
        • 1970-01-01
        相关资源
        最近更新 更多