Forum: Ruby on Rails Question about state during subsequent calls of an action

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
2a771471ac58aaabdeb883001d6b7c07?d=identicon&s=25 asymmetric (Guest)
on 2009-05-20 16:34
(Received via mailing list)
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
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2009-05-20 16:41
(Received via mailing list)
On May 20, 2:14 pm, asymmetric <oxy...@gmail.com> wrote:
>
> 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
2a771471ac58aaabdeb883001d6b7c07?d=identicon&s=25 asymmetric (Guest)
on 2009-05-21 03:23
(Received via mailing list)
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...@gmail.com>
This topic is locked and can not be replied to.