ActiveAdmin嵌套表单与新项目

时间:2014-04-17 10:00:24

标签: ruby-on-rails ruby admin activeadmin nested-forms

我遇到ActiveAdmin和嵌套表单的问题:当我用一些回复创建一个新问题时,我收到一个错误(问题不能为空)。但是,如果我创建一个问题然后,在更新时,我添加一些回复一切顺利。

任何人都可以帮助我吗?

这是我的代码

# models/question.rb
class Question < ActiveRecord::Base
  attr_accessible :points, :text, :replies_attributes
# RELATIONS
  has_many :replies

  accepts_nested_attributes_for :replies
end

# models/reply.rb
class Reply < ActiveRecord::Base
  attr_accessible :correct, :question_id, :text, :question
# VALIDATIONS
  validates_presence_of :text, :question_id
# RELATIONS
  belongs_to :question
end

# admin/question.rb
ActiveAdmin.register Question do
  form do |f|
    f.inputs "Details" do
      f.input :text
      f.input :points
    end
    f.inputs do
      f.has_many :replies do |rp|
        rp.input :text
        rp.input :correct
      end
    end
    f.actions
  end
end

1 个答案:

答案 0 :(得分:0)

...也许:inverse_of可以帮到你。

What does inverse_of do? What SQL does it generate?