ActiveAdmin with has_many problem; 未定义的方法‘ new_record?’

我正在尝试为一个与 Step 有 _ many 关系的 Recipe 模型自定义 ActiveAdmin 表单。

class Recipe < ActiveRecord::Base
has_many :steps
end


class Step < ActiveRecord::Base
acts_as_list :scope => :recipe


belongs_to :recipe
end

我在 ActiveAdmin 文件中有以下与此相关的内容:

form do |f|
f.has_many :steps do |ing_f|
ing_f.inputs
end
end

试图加载表单时引发以下错误:

Nil 的未定义方法‘ new _ record?’: NilClass

到目前为止,我已经将它隔离到 has _ many 方法中,但是我在这里迷失了方向。任何建议和帮助将不胜感激!

23640 次浏览

go to your Recipe model and add the following line

accepts_nested_attributes_for :steps

The line is required by formtastic, not active admin. Check https://github.com/justinfrench/formtastic for formtastic documentation

class Recipe < ActiveRecord::Base


attr_accessible :step_attributes


has_many :steps


accepts_nested_attributes_for :steps


end