ActiveAdmin具有has_many问题;未定义的方法“ new_record?”


75

我正在尝试为与Step具有has_many关系的配方模型自定义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

当我尝试加载表单时引发以下错误:

未定义的方法“ new_record?” 对于nil:NilClass

到目前为止,我已经将它隔离到has_many方法,但是我迷失了它。任何建议和帮助,将不胜感激!

Answers:



2
class Recipe < ActiveRecord::Base

    attr_accessible :step_attributes

    has_many :steps

    accepts_nested_attributes_for :steps

end
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.