asymmetric
2009-May-20 13:14 UTC
Question about state during subsequent calls of an action
Hi! i''m developing a rails application for a university assignment. i''ll spare you the details as i think my question is much more general. i have a model, called TreasureHunt, which contains a class variable, @@idno, and a reader class method, TreasureHunt.idno. in the initializer, i increment the @@idno variable, to keep track of the number of objects instantiated. then i have a controller, treasurehunt_controller, with an action, called load, which does some things (loads a treasurehunt and blah blah blah). in the load method, i create a treasurehunt object, thus supposedly incrementing the @@idno variable. the problem is i''m not (incrementing the variable). when i debug the app (using a flash that gets displayed in my layout), the @@idno variable is always 1, even after subsequent calls of the load action. does anybody know why? do i need to store that state somewhere else? i''m pretty confused. thanks asy
Frederick Cheung
2009-May-20 14:40 UTC
Re: Question about state during subsequent calls of an action
On May 20, 2:14 pm, asymmetric <oxy...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> then i have a controller, treasurehunt_controller, with an action, > called load, which does some things (loads a treasurehunt and blah > blah blah). in the load method, i create a treasurehunt object, thus > supposedly incrementing the @@idno variable. > > the problem is i''m not (incrementing the variable). > > when i debug the app (using a flash that gets displayed in my layout), > the @@idno variable is always 1, even after subsequent calls of the > load action. > > does anybody know why?in development mode classes are reloaded between requests, so on the second request you get a brand new TreasureHunt class, with a brand new @@idno variable Fred> > do i need to store that state somewhere else? > i''m pretty confused. > > thanks > asy
asymmetric
2009-May-21 01:22 UTC
Re: Question about state during subsequent calls of an action
that was exactly the kind of answer i was looking for.. thanks a lot! asymmetric On May 20, 4:40 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On May 20, 2:14 pm, asymmetric <oxy...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > then i have a controller, treasurehunt_controller, with an action, > > called load, which does some things (loads a treasurehunt and blah > > blah blah). in the load method, i create a treasurehunt object, thus > > supposedly incrementing the @@idno variable. > > > the problem is i''m not (incrementing the variable). > > > when i debug the app (using a flash that gets displayed in my layout), > > the @@idno variable is always 1, even after subsequent calls of the > > load action. > > > does anybody know why? > > in development mode classes are reloaded between requests, so on the > second request you get a brand new TreasureHunt class, with a brand > new @@idno variable > > Fred > > > > > do i need to store that state somewhere else? > > i''m pretty confused. > > > thanks > > asy