ActiveAdmin具有has_many问题;未定义的方法“ new_record?” [英] ActiveAdmin with has_many problem; undefined method 'new_record?'

查看:69
本文介绍了ActiveAdmin具有has_many问题;未定义的方法“ 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆