1
我试图用茧宝石创建一些混合简单窗体的嵌套窗体,当我实现窗体时,我得到Undefined method simple_field_for
。我对Rails相当陌生,所以如果这是一个愚蠢的修复,我会提前道歉,但我已经扫描Stack Overflow和Google足够长的时间,因为我已经决定发布并询问。我正在遵循的教程在视图中使用haml。以下是我的代码,请让我知道是否需要发布其他信息以帮助解决错误。谢谢!未定义的方法`simple_field_for'为#<#<Class:0x007fa76a658768>:0x007fa76a962d50>
总计错误消息:
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'
再次,让我知道是否需要包含任何其他文件。谢谢!
谢谢....不能相信我错过了。 – Tucker