有关创建调查的精彩轨道广播: http://railscasts.com/episodes/196-nested-model-form-part-1
这是我创建调查所需的一切,但我希望用户在一个页面上一次登录一个或多个完整的调查。
任何人都可以扩展本教程来存储多项选择调查的答案吗?有一个很好的教程吗?
以下是我的尝试
我正在将Devise用于用户帐户。
User
has_many :answers_users
has_many :answers, through: :answers_users
has_many :questions, through: :answers_users
has_many :surveys, through: :answers_users
Survey
has_many :questions, autosave: true
has_many :answers_users, autosave: true
has_many :users, through: :answers_users
has_many :answers, through: :questions
question
belongs_to :survey
has_many :answers
has_many :answers_users
has_many :users, through: :answer_users
Answer
belongs_to :question
has_many :users, through: :answers_users, autosave: true
AnswersUsers
belongs_to :user
belongs_to :answer
belongs_to :question
belongs_to :survey
我的表格
<%= simple_form_for [current_user], :url => competition_enter_path, :method => :POST do |f| %>
<% @surveys.each do |survey| %>
<%= survey.name %>
<br />
<% survey.questions.each do |qq| %>
<%= simple_fields_for qq do |q| %>
<h3><%= qq.question %></h3>
<%= q.association :answers,
label: false,
collection: qq.answers,
as: :"#{qq.question_type.code}",
:label_method => :answer,
required: true
%>
<% end %>
<% end %>
<% end %>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
我得到的输出是(有一个答案)
Parameters: {"utf8"=>"✓", "authenticity_token"=>"SOUAVgw261HrMLUxkVQvlKrigSStZs+uHqHePizgBxE=", "question"=>{"answer_ids"=>"11"}, "commit"=>"Update User", "competition_id"=>"1"}
但没有什么可以储蓄的。我不知道在控制器中放什么,因为我需要回答也存储Question_id和Survey_id的答案,对吗?
有人可以帮忙吗?