I am building a multiple choice survey with a set of fixed questions and fixed answers. A question has_many answers and an answer belongs_to question. The questions and answers will be seed data in the db and will be written in the seeds.rb file.
I am trying to figure out how to relate the surveys to the questions and answers. Users can pick from taking a short or long survey, each of which will have a different amount of questions. So a survey needs to be able to keep track of which questions it has, and the answers chosen for each question. I've started out with this relationship for surveys and questions:
class Survey < ActiveRecord::Base
has_and_belongs_to_many :questions
end
class Question < ActiveRecord::Base
has_and_belongs_to_many :surveys
end
Now I can't figure out how to put answers into this. A question has_many :answers, but how do i relate the answers to surveys? I was thinking a has_many through relationship, but I can't see how that would work.
Any ideas?