Accessing cookie and session objects


#1

Is it possible to directly access session and cookie objects from within
a Model? When I try to read the session object in my User Model I get
the following error:

NameError (undefined local variable or method `session’ for User:Class):

I could pass attributes taken from the session into my method in the
User Model, but this seems to go against DRY.

-Lindsay


#2

Am Freitag, den 03.03.2006, 15:14 +0100 schrieb Lindsay B.:

Is it possible to directly access session and cookie objects from within
a Model? When I try to read the session object in my User Model I get
the following error:

NameError (undefined local variable or method `session’ for User:Class):

I could pass attributes taken from the session into my method in the
User Model, but this seems to go against DRY.

No, ActiveRecord models have no direct access to the ActionController
objects or methods. Handling sessions or cookies within the model would
breach against the MVC (Model, View, Controller) principle what is the
base Rails is build upon. It goes over DRY.

If you need some information about session parameters in the model, pass
them to model methods.


Norman T.

http://blog.inlet-media.de


#3

Handling sessions or cookies within the model would
breach against the MVC (Model, View, Controller) principle what is the
base Rails is build upon. It goes over DRY.

Yes, I suppose MVC should trump DRY. I’ll just send my session
attributes to the Model.

thanks
-Lindsay