views:

27

answers:

2

I have a Rails app that lets users create tutorials and quizzes. There are many users taking the quizzes and many quizzes in a tutorial. My client wants the quiz results to persist when a student navigates away from the quiz. So the use case would be:

  • User starts to take quiz
  • User answers some of the questions
  • User navigates away from quiz to check a fact in the tutorial
  • User goes back to quiz and their answers are still there
  • User finishes quiz and submits

Now this would be pretty easy to do if I enforced a "Save" submit so that the answers could be stored in a session or whatever, but the client (and I agree) thinks people will not remember to save before navigating away.

Looking for advice on how to approach this. I'm thinking an observer and cookies.

A: 

There can be two ways to handle this.

  • Prompt the user to save before navigating away from the page For example
     <script language='javascript' type='text/javascript'>
      window.onbeforeunload = function (evt) {
        return "This is a demonstration that you are leaving me";
      }
    </script>
   
  • AutoSave content, when each question is answered using Ajax ( using some type of eventhandlers, like click, change or blur
Rishav Rastogi
A: 

I ended up using a remote function to autosave the content.

kim griggs