AJAX call creates new instance of controller class

Hi All,

I have a problem with the AJAX requests in rails. Consider a
controller class C with some methods M1, M2, M3. For this controller
class I have a view V.rhtml.

Within V.rhtml I have a periodically_call_remote AJAX request script
to call the method M1 after every 5 seconds say.

However, when I do this , I observe that for every new AJAX request a
new instance of my controller class C gets created with default values
of the instance variables, whereas I need the values of variables from
my current instance of the Class C .

Any clues as to how can I maintain a single class instance for all of
my AJAX requests from a particular client.

TIA
~Shishir

Shishir S. wrote:

However, when I do this , I observe that for every new AJAX request a
new instance of my controller class C gets created with default values
of the instance variables, whereas I need the values of variables from
my current instance of the Class C .

Any clues as to how can I maintain a single class instance for all of
my AJAX requests from a particular client.

TIA
~Shishir

Hiya Shishir,

You need to remember that HTTP is essentially a stateless protocol -
every ajax call you make is similar to just doing a reload in your
webpage.

The same principles will apply to keep your current state i.e. add
get/post parameters to your request, use session or use cookies so that
you can determine the current state in your controller.

Hope that helps.

Luke

Shishir S. wrote:

new instance of my controller class C gets created with default values
of the instance variables, whereas I need the values of variables from
my current instance of the Class C .

Any clues as to how can I maintain a single class instance for all of
my AJAX requests from a particular client.

TIA
~Shishir

Save whatever you need to persist between AJAX calls to the session
object.


Michael W.

I am trying to use the session[:object] but the mongrel server throws
some error. :frowning:

Can you give some example code as to how to implement the same.

Thanks,
Shishir

On Sep 19, 3:20 pm, Luke P. [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