Topic: Rails nested forms

down vote
I have tables Evaluation(id, user, evaluated_user, date), Questions(id, question), Answers(id, answer, question_id), Opinion(evaluation_id, question_id, answer_id). The idea is to have multiple polls in one page. I want to do a form where user can fill all questions in one page and later update his answers. One evaluation contains multiple opinions which should be filled in one page as I wrote. I am wondering how to do it. I have to use nested form for one question which is one row in Opinion but how to make N nested forms and then make post request to get all opinion objects. I really have no idea how to do it so it would be great if someone can help. Thanks in advance.

My current models:

class Answer < ActiveRecord::Base
belongs_to :question

class Evaluation < ActiveRecord::Base
  has_many :opinion

class Opinion < ActiveRecord::Base
  belongs_to :evaluation
  belongs_to :question
  belongs_to :answer
  accepts_nested_attributes_for :question

class Question < ActiveRecord::Base
  has_many :answer
  accepts_nested_attributes_for :answer
My controller:

def new
  @opinion =
  3.times do
    question = @opinion.build_question
    5.times { question.build_answer }
  @questions = Question.all
  @answers = Answer.all
I need 3 and 5 not to be constants and to get them from DB and size for every question and total size of questions.