0

我需要帮助! 我有2种型号的一项调查显示:Active Admin中的嵌套表格

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 

有模型的问题如下:(看来这assocciations是正确的)

​​

另外在主动管理:

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 

它有一个美丽的形式,不创建一个实际的问题对象!为什么? 我尽力解决了这个问题,但我失败了。

回答

0

这可能是因为您已为accept_nested_attributes_for获得双重级别。为什么不创建一个有很多民意测验答案的民意调查回答的新模型?

然后,您将在PollResponse类中设置一个accep_nested_attributes_for:poll_answers。

然后,您不仅可以排除您的表单问题,还可以跟踪回答投票(可能)的人员和投票响应的创建时间。 PollResponses模型也必须属于民意调查,以区分哪个民意测验正在被回答。

+0

和有关创建答案变种是什么?从管理面板? – prikha

+0

不工作? [Ryan的情节](http://railscasts.com/episodes/196-nested-model-form-part-1)与活跃管理员? – prikha

+0

我也很感兴趣,如果有人有解决方案... –

0

试图通过创建对象,

f.has_many :poll_questions, PollQuestion.new do |question| 
    question.input :text 
end