Session: a poor man's global?

As I learn Rails I find myself all too often tempted to dump
something into the session hash just because I can’t think of a
better way to make it briefly persistent (no oxymoron intended!).

For instance, I have report that allows all sorts of changes by the
user. He can set filters on the data, sort it in different ways, and
so on. Different Actions get involved, but each of them needs to see
the underlying data. It makes things a lot easier if they can just
pull it from the session. But I always feel a little bit ‘dirty’ in
doing so.

How do others handle these sorts of things?

-George

George B. wrote:

For instance, I have report that allows all sorts of changes by the
user. He can set filters on the data, sort it in different ways, and
so on. Different Actions get involved, but each of them needs to see
the underlying data. It makes things a lot easier if they can just
pull it from the session. But I always feel a little bit ‘dirty’ in
doing so.

This is all off the top of my head…

What if you created a Search object. A full-blown Rails model. As your
users customized their query options, you saved the changes just like
any other model. This way you’d also be able to recall a person’s
preferences later.

Then, in session, you can simply store the ID of that person’s search
preferences.

Just a thought…

  • Daniel

This is exactly my approach, and I’m working on extracting a plugin
that deals with the find options extraction automatically. Aside from
being able to easily persist to the database, it also makes search
forms a snap. See my writeup at:

http://darwinweb.net/article/Implementing_Advanced_Search_In_Rails_Using_Search_Models

The idea is still somewhat rough in that article, but by the time I
get the plugin done it should be much cleaner to implement.

On Jun 13, 4:01 pm, Daniel W. [email protected]

dasil003 wrote:

This is exactly my approach…

Sweet! I’ve actually been thinking about such a solution for quite some
time (I just don’t do it because none of my projects are search
intensive).

I wish you the best of luck Dasil – keep us informed of your progress.
:slight_smile:

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs