Pass an object or an id?

Hello,

I understand that it is not good practice in rails to store objects in
the session[] and to instead just store id’s of model objects… could
someone please explain why this is?

If this is true, i was wondering if it was also better practice to pass
id’s between methods as opposed to passing objects?

Is the performance of the application a factor in deciding this?

I also have an issue of whether to have fairly large controller methods
or to split them up and use redirect_to between the methods… basically,
the large method would be reused a lot and so would have to have many
‘if’ statements in to account for all instances of its use… or the
smaller ones would account for the different instances and would use
redirect_to to use common code ??

Any thoughts on these issues would be very much appreciated!

hi,

Can you point me to the article or which book you have read that
discourages in storing objects in session[]

Thanks

On Jan 31, 8:05 am, James S. [email protected]

On 1/30/07, James S. [email protected] wrote:

Is the performance of the application a factor in deciding this?

Posted via http://www.ruby-forum.com/.

This will answer part of your question:

http://www.therailsway.com/2007/1/10/assetsgraphed-part-2


Zack C.
http://depixelate.com

Hi James,

james_027 wrote:

Can you point me to the article or which book you
have read that discourages in storing objects in session[]

“Agile Web D. with Rails”, p. 314
“You probably don’t want to store massive objects in session data – put
them in the database and reference them from the session.”

The key here is to understand that if, for example, you have an object
that
‘has many’ other objects, when you store the parent object in the
session,
all the children get stored too.

hth,
Bill

On 1/31/07, james_027 [email protected] wrote:

I see you point bill, what if the object doesn’t have child objects?

There’s also the staleness issue. Loading from db on each request
ensures that you’re working with current data.

Isak

I see you point bill, what if the object doesn’t have child objects?
Is there a way to tell rails that by default the child object will not
be retrieve until needed?

will it be much more efficient to store the id of the object in the
session and perform a lot of find operation (sql query)? how do we
evaluate the two solutions?

thanks