【发布时间】:2016-05-19 22:42:28
【问题描述】:
我正在尝试使用 cocoon gem 创建一些与简单表单混合的嵌套表单,当我实现表单时我得到了Undefined method simple_field_for。我对 Rails 很陌生,所以如果这是一个愚蠢的修复,我提前道歉,但我已经扫描了 Stack Overflow 和谷歌足够长的时间,我决定只发布并询问。我正在关注的教程在视图中使用了haml。以下是我的代码,如果需要发布其他内容来帮助解决错误,请告诉我。谢谢!
总错误消息:
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'
再次,让我知道是否需要包含任何其他文件。谢谢!
【问题讨论】:
标签: ruby-on-rails ruby-on-rails-4 haml simple-form cocoon-gem