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