Topic: Rails nested forms

0
down vote
favorite
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
end

class Evaluation < ActiveRecord::Base
  has_many :opinion
end

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

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

def new
  @opinion = Opinion.new
  3.times do
    question = @opinion.build_question
    5.times { question.build_answer }
  end
  @questions = Question.all
  @answers = Answer.all
end
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.