# Is there an object to store something across the sessions?

**URL:** <https://www.ruby-forum.com/t/is-there-an-object-to-store-something-across-the-sessions/80834>\
**Category:** Rails\
**Created:** [December 31, 2006, 12:40am UTC](https://www.ruby-forum.com/t/is-there-an-object-to-store-something-across-the-sessions/80834 "2006-12-31T00:40:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![backz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/9f8e36/32.png) [@backz](https://www.ruby-forum.com/u/backz)\
**Post date:** [December 31, 2006, 12:40am UTC](https://www.ruby-forum.com/t/is-there-an-object-to-store-something-across-the-sessions/80834/1 "2006-12-31T00:40:47Z")

</div>

# Just like servlet context in java web development. In rails 1.1.6, the latest version on [rubyforge.org](http://rubyforge.org), I can do like this: create a model without database tables bar.rb

# class Bar @@v=0 def inc @@v+=1 end end

# and create a controller foo\_controller.rb

# class FooController \< ApplicationController def index render\_text Bar.new.to\_s end end

This works on different sessions or browsers.

But it doesn’t work with Rails 1.2rc1 (1.1.6.5618). Why?  
Are there something changed in 1.2rc1?  
How can I do the same thing in 1.2rc1?

---

<div class="post-metadata">

**Author:** ![backz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/9f8e36/32.png) [@backz](https://www.ruby-forum.com/u/backz)\
**Post date:** [December 31, 2006, 12:48am UTC](https://www.ruby-forum.com/t/is-there-an-object-to-store-something-across-the-sessions/80834/2 "2006-12-31T00:48:53Z")

</div>

Hi,

@@ indicates an instance variable, not a session object.  
if you wish to use session object, just define one by simply adding a  
key and value to the session hash. ex.

session[:name] = “elad”  
session[:user] = User.find\_by\_name(“elad”)

etc. etc.

hope this helps,

---

<div class="post-metadata">

**Author:** ![backz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/9f8e36/32.png) [@backz](https://www.ruby-forum.com/u/backz)\
**Post date:** [December 31, 2006, 1:02am UTC](https://www.ruby-forum.com/t/is-there-an-object-to-store-something-across-the-sessions/80834/3 "2006-12-31T01:02:56Z")

</div>

Hi, please read the AWDwRv2 on using sessions. One would never write  
such code for web applications that need to maintain or share state  
between sessions. Thus, this code would exhibit undesireable behavior  
when used with the web development context.

Good luck,

-Conrad
