I am attempting to build a learning application that has a quiz on it. The quiz is made up of several steps.
I am using aasm
to track the the user's state on the quiz.
There are 3 states:
1.not started (Default state)
2.in progress
3.completed
I am tracking the state because when a user starts the quiz, logs out and then returns they will be able to continue.
There are 2 event transitions:
start
& finish
I understand that I call these on quiz to set the state - Quiz.start!
& Quiz.finish!
I can tell what state the user is on if the quiz step they're on has a parent then they're in progress and if the quiz step they're on has no children then they have finished. Something like this:
if quiz.parent
quiz.start!
else quiz.children == 0
quiz.finish!
end
All I want to know is where I put the above logic to set the state? I don't think I put it in my controller. Do I have to put it in the Quiz class? Do I use a define a method set_state with the above logic in it? If so, how do I use it?
I have read the aasm
docs and kind of get it but my brain is fried and could just use a bit of guidance.
Thanks in advance.