75

我正在尝试为与 Step 具有 has_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

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

未定义的方法`new_record?对于零:NilClass

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

4

2 回答 2

166

转到您的食谱模型并添加以下行

accepts_nested_attributes_for :steps

formtastic 需要该行,而不是活动管理员。查看https://github.com/justinfrench/formtastic以获取 formtastic 文档

于 2011-08-31T06:54:22.363 回答
2
class Recipe < ActiveRecord::Base

    attr_accessible :step_attributes

    has_many :steps

    accepts_nested_attributes_for :steps

end
于 2015-10-14T09:07:01.580 回答