Active Admin中的嵌套表单 [英] Nested form in Active Admin
本文介绍了Active Admin中的嵌套表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要帮助! 我有2个调查模型:
I need help! I have 2 models for a Survey:
class Poll < ActiveRecord::Base
has_many :poll_questions, :dependent => :destroy
accepts_nested_attributes_for :poll_questions, :reject_if => lambda { |a| a[:text].blank? }, :allow_destroy => true
end
存在以下问题的模型:(看来这些关联是正确的)
There is model for questions as follows: (it seems these assocciations are correct)
class PollQuestion < ActiveRecord::Base
belongs_to :poll
has_many :poll_answers, :dependent => :destroy
accepts_nested_attributes_for :poll_answers, :reject_if => lambda { |a| a[:text].blank? }, :allow_destroy => true
end
活动管理员中的其他内容:
In addition in active Admin:
ActiveAdmin.register Poll do
form do |f|
f.inputs "Main poll" do
f.input :title
f.input :description
end
f.inputs do
f.has_many :poll_questions do |question|
question.input :text
end
end
f.buttons
end
end
它具有漂亮的形式,不会创建实际的问题对象!为什么? 我已经尽力解决了这个问题,但是失败了.
It has a beautiful form that doesnt create an actual question object! why? I've tried my best to solve the problem, but I've failed.
推荐答案
尝试创建对象,
f.has_many :poll_questions, PollQuestion.new do |question|
question.input :text
end
这篇关于Active Admin中的嵌套表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文