Sessions in Rails:
Code:
session[:answers] = your_answers
and:
Code:
your_answers = session[:answers]
I think the Answers table should have:
Code:
question_id integer
correct tinyint|bool
Then you can check it like this:
Code:
answer = Answer.find(params[:answer_id])
if answer.correct?
#correct
else
#incorrect
end
Or if your question has only one correct answer:
model question:
Code:
belongs_to :correct_answer, :class_name => "Answer", :foreign_key => "correct_answer_id"
table questions:
Code:
correct_answer_id integer
Check:
Code:
answer = Answer.find(params[:id])
if answer.question.correct_answer == answer
#correct
else
#incorrect
end
Bookmarks