persisting an object

ok this is really basic rails question, but how do I keep an object alive between controller action? I thought I could create an object and it would remain alive, but I am guessing the controller object gets recreated each time?

ok this is really basic rails question, but how do I keep an object alive between controller action? I thought I could create an object and it would remain alive, but I am guessing the controller object gets recreated each time?

Rajinder, you can store the object in a session. For example, you can do the following:

Store:

session[:object_to_persist] = an_object

Retrieve:

some_local_variable = session[:object_to_persist]

For further information, I would recommend reading the relevant section from “Agile Web Development with Rails 3rd” by Dave Thomas et al.

Good look,

-Conrad

Conrad Taylor wrote:

    ok this is really basic rails question, but how do I keep an object     alive between controller action? I thought I could create an object     and it would remain alive, but I am guessing the controller object     gets recreated each time?

Rajinder, you can store the object in a session. For example, you can do the following:

Store:

session[:object_to_persist] = an_object

Retrieve:

some_local_variable = session[:object_to_persist]

For further information, I would recommend reading the relevant section from "Agile Web Development with Rails 3rd" by Dave Thomas et al.

Hi Conrad,

thanks I was not sure session object was the right way to do things. I've got 3 books on Rails and I'm hoping to get "Agile Web Development with Rails 3rd" soon =) but I'll will check out the section now.

Conrad Taylor wrote:

ok this is really basic rails question, but how do I keep an object

alive between controller action? I thought I could create an object

and it would remain alive, but I am guessing the controller object

gets recreated each time?

Rajinder, you can store the object in a session. For example, you can do the following:

Store:

session[:object_to_persist] = an_object

Retrieve:

some_local_variable = session[:object_to_persist]

For further information, I would recommend reading the relevant section from “Agile Web Development with Rails 3rd” by Dave Thomas et al.

Hi Conrad,

thanks I was not sure session object was the right way to do things. I’ve got 3 books on Rails and I’m hoping to get “Agile Web Development with Rails 3rd” soon =) but I’ll will check out the section now.

Rajinder, you can read the section on “Cart Creation”. Also, there’s later section(s) in the book that goes into greater detail.

Good luck,

-Conrad

Conrad Taylor wrote:

    Conrad Taylor wrote:

           ok this is really basic rails question, but how do I keep an         object            alive between controller action? I thought I could create an         object            and it would remain alive, but I am guessing the controller         object            gets recreated each time?

        Rajinder, you can store the object in a session. For example,         you can do the following:

        Store:

        session[:object_to_persist] = an_object

        Retrieve:

        some_local_variable = session[:object_to_persist]

        For further information, I would recommend reading the relevant         section from "Agile Web Development with Rails 3rd" by Dave         Thomas et al.

    Hi Conrad,

    thanks I was not sure session object was the right way to do things.     I've got 3 books on Rails and I'm hoping to get "Agile Web     Development with Rails 3rd" soon =) but I'll will check out the     section now.

Rajinder, you can read the section on "Cart Creation". Also, there's later section(s) in the book that goes into greater detail.

Conrad, thanks again =) it's working like a charm and I'll read the entire section on "Cart Creation" tonight!

Kind Regards, Rajinder Yadav