Forum: Ruby on Rails Is there an object to store something across the sessions?

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.
A07fb51713451ac7d74a62457c38839e?d=identicon&s=25 Daniel King (Guest)
on 2006-12-31 00:40
(Received via mailing list)
Just like servlet context in java web development.
In rails 1.1.6, the latest version on 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?
72f8ab180f81f9c544e2b58da399c0be?d=identicon&s=25 Elad Meidar (eizesus)
on 2006-12-31 00:48
(Received via mailing list)
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,
40db9e75b3f5899258e3bdc0c9210154?d=identicon&s=25 Conrad Taylor (Guest)
on 2006-12-31 01:02
(Received via mailing list)
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
This topic is locked and can not be replied to.