# Question about state during subsequent calls of an action

**URL:** <https://www.ruby-forum.com/t/question-about-state-during-subsequent-calls-of-an-action/168411>\
**Category:** Rails\
**Created:** [May 20, 2009, 4:34pm UTC](https://www.ruby-forum.com/t/question-about-state-during-subsequent-calls-of-an-action/168411 "2009-05-20T16:34:27Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![asymmetric](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/d9b06d/32.png) [@asymmetric](https://www.ruby-forum.com/u/asymmetric)\
**Post date:** [May 20, 2009, 4:34pm UTC](https://www.ruby-forum.com/t/question-about-state-during-subsequent-calls-of-an-action/168411/1 "2009-05-20T16:34:27Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![asymmetric](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/d9b06d/32.png) [@asymmetric](https://www.ruby-forum.com/u/asymmetric)\
**Post date:** [May 20, 2009, 4:41pm UTC](https://www.ruby-forum.com/t/question-about-state-during-subsequent-calls-of-an-action/168411/2 "2009-05-20T16:41:28Z")

</div>

On May 20, 2:14 pm, asymmetric [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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

---

<div class="post-metadata">

**Author:** ![asymmetric](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/d9b06d/32.png) [@asymmetric](https://www.ruby-forum.com/u/asymmetric)\
**Post date:** [May 21, 2009, 3:23am UTC](https://www.ruby-forum.com/t/question-about-state-during-subsequent-calls-of-an-action/168411/3 "2009-05-21T03:23:31Z")

</div>

that was exactly the kind of answer i was looking for… thanks a lot!

asymmetric

On May 20, 4:40 pm, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
