I’m building an online test app. In my app, one question can be a True/False question, Single choice (only one answer is accepted), Multi choice (many answers are accepted). I create models:
class Question < ActiveRecord::Base
has_many :answers
end
class Answer < ActiveRecord::Base
belongs_to :question
end
The Question model will have a question_type_id to check it is a T/F, Single or Multi choice.
The Answer model will have a column called content typed text, and i will have a boolean column called correct to know which answer is accepted. With single and multi choice questions, i think answers are text will be fine to store in content column, but with True/False question, is it good idea if i only store answers is text like ‘True’, ‘False’ in content column and set a True for answer is accepted in correct column? I don’t know another better way to deal with True/False question, can anybody help me?
Storing the boolean values as strings seems like the most reasonable way to accomplish what you want. I would recommend normalizing the values on save so that true and false always look the same when you fetch an answer.