So today I had to debug a problem I had with one of my clients applications. In the session I was storing how a page was being sorted. The problem was that the sort was not saving to the session properly. My model was setup with a has_many relationship to another model. It was in the second model that I was storing some information. But when I would retrieve it from the session the values were going back to the default. Below is a example of how I was using the session.
sort.columns.set_id = 2
session[:sort] = sort
Now at the beginning of my list action I would pull back the sort from the session so I could compare the values.
col_id = session[:sort].columns.set_id
I was expecting to get 2 when I checked the value of col_id. Instead I got the default of 1. It seems that the session was not saving the stored value for the column object. I might be doing this wrong but I would have expected the columns model to persist the correct value as it was being accessed through the sort model and the sort model was being saved to the session.
To make a long story short, be careful what you store in your session, and always check your values before assuming they are right.
Comments