【问题标题】:Missing partial error vs button not showing while using simple_form & cocoon使用 simple_form 和 cocoon 时缺少部分错误与按钮未显示
【发布时间】:2016-05-20 01:32:59
【问题描述】:

我对 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 按钮和文本区域不会显示。我正在按照 cocoon 文档 (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'

【问题讨论】:

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


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2023-03-23
      • 2013-09-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-02-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多