Daniel King
2006-Dec-30 14:07 UTC
Is there an object to store something across the sessions?
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?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Elad Meidar - Creopolis.com
2006-Dec-30 23:42 UTC
Re: Is there an object to store something across the sessions?
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,
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Conrad Taylor
2006-Dec-31 00:00 UTC
Re: Is there an object to store something across the sessions?
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 On 12/30/06, Daniel King <cnkknd-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > 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? > > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---