Topic: Sessions in Model

I've always wondered why you cannot access sessions within the model. I don't think it'd violate the "rules" of MVC, and surely it wouldn't cause that much extra strain?

(I'm wondering because I wanted to create my own plugin simply for education on how to create plugins, and I thought that I'd eventually need a session in the model.)

Re: Sessions in Model

The controller layer is supposed to be a "filter" in a sense to all outside input variables. The session falls along these lines and therefore cannot be accessed directly in the model. This makes the models more flexible because you can change where you store the variable (perhaps in a cookie instead of a session) and you don't have to change the model layer to do this. It also makes testing the model layer easier.

There are hacks to get around this, but I don't recommend it.

Railscasts - Free Ruby on Rails Screencasts