使用simple_form&时缺少部分错误vs按钮未显示茧

时间:2016-02-09 21:36:02

标签: ruby-on-rails ruby-on-rails-4 haml simple-form cocoon-gem

我对rails非常陌生,我试图一起使用cocoon和simple_form为我后面的食谱应用教程创建一些嵌套表单。他们使用haml,当我似乎遵循haml的正确缩进过程时,我得到了一个缺失的部分错误。

错误消息:

Missing partial recipes/_ingredient_fields, application/_ingredient_fields with {:locale=>[:en], :formats=>[:html], :variants=>[], :handlers=>[:erb, :builder, :raw, :ruby, :coffee, :haml, :jbuilder]}.

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

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

如果我选中.linkslink_to_add_association行,则视图会显示,但ingredient按钮和文本区域不会显示。我遵循了茧文件(https://github.com/nathanvda/cocoon)中规定的程序,但我似乎无法让它发挥作用。以下是每个文件的完整代码。请告诉我是否需要包含任何其他文件。在此先感谢您的帮助!

_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_fields_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'

1 个答案:

答案 0 :(得分:1)

您的文件名为_ingredients_fields,它期待_ingredient_fields(单一成分)