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