#<#<Class:0x007fa76a658768>:0x007fa76a962d50> 的未定义方法“simple_field_for”

Undefined method `simple_field_for' for #<#<Class:0x007fa76a658768>:0x007fa76a962d50>

我正在尝试使用 cocoon gem 创建一些与简单表单混合的嵌套表单,当我实现表单时我得到了 Undefined method simple_field_for。我是 rails 的新手,所以如果这是一个愚蠢的修复,我提前道歉,但我已经扫描了 Stack Overflow 和 Google 足够长的时间,我决定只 post 和问。我正在学习的教程在视图中使用了 haml。下面是我的代码,如果需要 posted 来帮助解决错误,请告诉我。谢谢!

错误消息总数:

undefined method `simple_field_for' for #<#<Class:0x007fa76a658768>:0x007fa76a962d50>

.row
   .col-md-6
     %h3 Ingredients
     #ingredients
      = f.simple_field_for :ingredients do |ingredient| #this is the line throwing the error
        = render 'ingredients_fields', f: ingredient
      .links
        = link_to_add_association 'Add Ingredient', f, :ingredients, class: 'btn btn-default add-button'

部分文件抛出错误:_form.html.haml

= simple_form_for @recipe, html: { multipart: true } do |f|
    - if @recipe.errors.any?
        #errors
          %p
           = @recipe.errors.count
           Prevented this recipe from saving.
          %ul
           - @recipe.errors.full_messages.each do |msg|
             %li= msg
    .panel-body
        = f.input :title, input_html: { class: 'form-control' }
        = f.input :description, input_html: { class: 'form-control' }
        = f.input :image, input_html: { class: 'form-control' }

        .row
          .col-md-6
            %h3 Ingredients
            #ingredients
              = f.simple_field_for :ingredients do |ingredient|
                = render 'ingredients_fields', f: ingredient
              .links
                = link_to_add_association 'Add Ingredient', f, :ingredients, class: 'btn btn-default add-button'

    = f.button :submit, class: 'btn btn-primary'

成分字段部分:_ingredients_fields.html.haml

.form-inline.clearfix
    .nested-fields
        = f.input :name, input_html: { class: 'form-input form-control' }
        = link_to_remove_association "Remove", f, class: 'form-button btn btn-default'

再次提醒,如果需要包含任何其他文件,请告诉我。谢谢!

simple_fields_for,不是simple_field_for。您缺少 s.

阅读 Simple Form Documentation 了解更多信息。