Context
I'm new to app development in Rails so please let me know if I am missing something obvious about saving/storing states in Rails. I'm using the Wicked gem in my app to guide users through a medical assessment that has the following steps:
- Personal information
- General medical questions
- Specific disease questions
- Consent
- Submit
Problem
If users leave at a certain part of the assessment to check another page of the app, or if they accidentally close the browser, they lose all their progress.
What I have tried
I added a save button on every step that users can click to save the information they have entered so far, and upon leaving and coming back, they would have the information pre-filled for them. This is not the UX I'm looking for, however, because users will still have to start from the first step and just keep clicking next until they reach the step they were last on or use the navigation to find the step. I want the wizard to automatically open up where they left off.
I tried this approach where I add an attribute for the user called
:assessment_step
and I update it every time the user reaches a new step and go to the step if it exists whenever the user opens the wizard. This approach works but is very hacky and not scalable at all. As I add more steps, and more wizards, this will be a pain to maintain. Here is the code:class MedicalAssessmentController < ApplicationController include Wicked::Wizard steps :personal_info, :medical_questions, :disease_questions, :consent, :submit def show @user = current_user # default assessment step is 0 @steps = [:personal_info, :medical_questions, :disease_questions, :consent, :submit] case step when :personal_info if @user.assessment_step != 0: jump_to(@steps[@user.assessment_step]) @user.update_attribute(:assessment_step, 0) # set the step reached to step 0 when :medical_questions @user.update_attribute(:assessment_step, 1) when :disease_questions @user.update_attribute(:assessment_step, 2) when :consent @user.update_attribute(:assessment_step, 3) when :submit @user.update_attribute(:assessment_step, 4) end # DO MORE STUFF render_wizard end end
Things I read
I couldn't find any similar questions on SO or anywhere online. The Wicked gem docs don't really mention anything similar.