ActiveAdmin具有has_many问题;未定义的方法“ new_record?” [英] ActiveAdmin with has_many problem; undefined method 'new_record?'
问题描述
我正在尝试为与Step具有has_many关系的配方模型自定义ActiveAdmin表单。
I'm trying to customise a ActiveAdmin form for a Recipe model that has a has_many relationship with Step.
class Recipe < ActiveRecord::Base
has_many :steps
end
class Step < ActiveRecord::Base
acts_as_list :scope => :recipe
belongs_to :recipe
end
我有
form do |f|
f.has_many :steps do |ing_f|
ing_f.inputs
end
end
以下错误是当我尝试加载表单时抛出:
The following error is thrown when I try to load the form:
未定义的方法'new_record?'为nil:NilClass
undefined method `new_record?' for nil:NilClass
到目前为止,我已经将它与has_many方法隔离了,但是我迷失了它。
I've isolated it so far to the has_many method but I'm lost past this. Any advice and help would be appreciated!
推荐答案
转到您的Recipe模型并添加以下行
go to your Recipe model and add the following line
accepts_nested_attributes_for :steps
行是必需的,不是活动管理员。检查 https://github.com/justinfrench/formtastic 以获取详细的文档
The line is required by formtastic, not active admin. Check https://github.com/justinfrench/formtastic for formtastic documentation
这篇关于ActiveAdmin具有has_many问题;未定义的方法“ new_record?”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!