Saving instance variables between GETs

Am I approaching this the wrong way according to the Ruby on Rails
conventions?

I will explain the situation. I currently have a reporting system which
will create and eventually render a report based on some choices the
user has made in a GET request and eventually end up with a @report
object.

Depending on what report the user wants, the @report object contains
different structures. Now there is a button on the same site, which is
called download report. Once this is called a different function in the
controller is called and I no longer have the @report object. This
forces me to recreate the same @report object based on model data which
takes quite a lot of processing time.

Is there any way to save this object between the different controller
functions? The first thing that comes to mind is the session hash.
Storing the @report in here though corrupts the session and causes an
error when it is used again (every next call) because it can not
determine the type of the @report object.

How is a good RoR programmer supposed to tackle this problem?

Am I really the only one wondering about this? Or is my basic structure
of the application wrong?

On Apr 17, 2008, at 12:26 PM, Chris D. wrote:

Am I really the only one wondering about this? Or is my basic
structure
of the application wrong?

Your assumption of the basic structure is wrong. The HTTP protocol is
stateless so you need to use sessions (cookies, and possibly a
database) to establish the illusion of persistence. Every new request
creates a new instance of the controller that needs to handle it so
the instance variables (and the instance) in the previous request are
gone.

-Rob

Rob B. http://agileconsultingllc.com
[email protected]

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