Topic: Help with sessions and data modeling for class project

Hi, I'm currently making a quiz based learning game for a sustainability class. The front end is a mix of custom design and Twitter Bootstrap. The basic structure is interactive slides interspersed with quiz questions. Users will earn badges for levels of mastery; the first level is what I'm turning in.

I'm falling behind on the project, and it's due in a week. Though it seems pretty straightforward, I'm a little worried since I've never done data modeling or sessions.  I was hoping someone could look over what I had planned and tell me if it's ok or there are better alternatives. 

I'm confused as far as a) sessions and b) modeling badges. I've already got the bulk of user modeling, courtesy of Devise.

SESSIONS:
So the basic idea here is that I need to keep track of the user's progress as he or she goes through the slides/quizzes so that he can come back later. To do this, I would simple set a session hash, like

session[:lesson_id] = <an id to distinguish the lesson>
session[:slide] = <the current slide number>
session[:cum_score] = <cumulative score>

Is that all there is? Is there a better way to do this? Any general advice on sessions?

BADGES: Once the user reaches the final slide and has a high enough score, he or she will be awarded a badge. This seems a bit tricky: a many to many relationship.

So I picture three tables: 1) Users, 2) Awards, and 3) Badges

The badges table will hold all the different kinds of badges, while the Awards table will act as an association table and link a user_id to a badge_id. In other words, the awards table will have two columns, user_id and badge_id.

Does this sound about right? Thanks!

Re: Help with sessions and data modeling for class project

So the basic idea here is that I need to keep track of the user's progress as he or she goes through the slides/quizzes so that he can come back later. To do this, I would simple set a session hash, like

There is no guarantee that the cookie stored on the users pc will still be available at the next visit. In order to guarantee this requirement you have 2 options both invovle storing the progress in permanent torage (a user_progress table sounds good to me).

Your options are really about when to save and you have to decide what to save and how to retrieve the position. You could either automatically update a users progress record at the point in time when you were thinking of adding the progress to the session or you could have a button on your web pages (in a partial view perhaps) that will send an HTTP POST or HTTP PUT request back to your server and the resulting action can update the currently logged in users progress.

Whichever option you choose is up to you to decide which would provide the best user experience.

Sessions are GREAT, but they are about a session not about permanent storage. It's rails way of providing persistence (or state if you prefer) in a staeless environment and really only should be used for persisting data accross a site visitorsz current session (hence the term session).

As far as using a session is concerned that really is all there is to it, apart from deciding how you want session data stored but for this exercise I wouldn;t worry too much about storage options, however I prefer the session data stored in database. You can (and probably should) read more about this here if you wish.  http://guides.rubyonrails.org/security.html

BADGES: Once the user reaches the final slide and has a high enough score, he or she will be awarded a badge. This seems a bit tricky: a many to many relationship.

So I picture three tables: 1) Users, 2) Awards, and 3) Badges

The badges table will hold all the different kinds of badges, while the Awards table will act as an association table and link a user_id to a badge_id. In other words, the awards table will have two columns, user_id and badge_id.

Does this sound about right?

Yes
You already have a users table as you are using Devise and this is the table you should be using, although I would consider rolling out your own authentication system. It's dead simple to do. http://railscasts.com/episodes/250-auth … m-scratch. You will get far more control over what you are doing and you will understnad your code a lot better.

An award will beiong to a user, and a user will have many awards that's a one to meny relatioship between a user and awards
if a badge has many awards and an award also belongs_to a badge then you get an implicit many to many relationship between users and badges and that is EXACTLY the correct solution. Not many people get database design but what you have propsed is perfect. I'm impressed considering your self declared lack of experience in this area!

What you want and what you need are too often not the same thing!
When your head is hurting from trying to solve a problem, stop standing on it. When you are the right way up you will see the problem differently and you just might find the solution.
(Quote by me 15th July 2009)

Re: Help with sessions and data modeling for class project

James, thanks so much for your response.  Sorry for my delayed reply: I was very busy the past 3 days.

This is very thorough and helpful!

For the saving progress issue, I will create a button that goes to the next slide and updates the user's progress with an HTTP Post.

It seems like my badges idea works.  Thanks.  (BTW, not a complete newb with data modeling;  I've done it in tutorials, just not on my own.)

Again, thanks for taking time to answer!