How to validate results in quiz app in Rails
I want to create a rails app where admin user can create quiz + questions + answers and the user can take the quiz and get results with percentage of results. First part is done Admin can create quiz and questions, I am stuck on how user can take the quiz. Right now I have models:
training.rb
has_many :questions, inverse_of: :training
accepts_nested_attributes_for :questions, reject_if: :all_blank, allow_destroy: true
mount_uploader :image, ImageUploader
has_many :results
has_many :users
question.rb
belongs_to :training
validates_presence_of :question_name, :presence => true
has_many :results
has_many :answers, inverse_of: :question
accepts_nested_attributes_for :answers, reject_if: :all_blank, allow_destroy: true
answer.rb
enum status: { wrong: 0,
wright: 1
}
belongs_to :question
validates_presence_of :answer_content, :presence => true
result.rb
belongs_to :training
belongs_to :user
belongs_to :question
I was thinking to show the question with 4 answers and on the side to have checkbox, after the user check his answer he can push submit button and I can compare the status of answer(wrong or wright) and then to have the points.
But I'm stuck and I believe I didn't think well everything from beginning. Do you know a gem which can do what I want?
from Recent Questions - Stack Overflow https://ift.tt/2Mfmq29
https://ift.tt/2Mg4EvG
Comments
Post a Comment