On 28-Feb-10, at 1:46 PM, Nick Brown wrote: > Bob Hutchison wrote: > >> If you use @@vara it'll work, since vara will become a class variable >> of Play::Application >> >> The trouble with that is that there's only one @@vara and it'll be >> used for all requests by all users. I'm also thinking that you >> probably don't really want that. If you don't then you'll have to >> keep >> vara someplace else, and look for it in each request. > > OK, I'm with you so far. But here's what I want to do: there is one > value (such as: number of users currently online) that is shown on > every > page. Every page view reads this number and displays it. This value is > updated whenever someone logs in or out. > > What is the best way to handle that? That's quite a question. Well, you could do it as a class variable of Play::Application but that's probably not the best idea. Play::Application instances are created by Sinatra to handle requests, and that's probably all they are should be used for. If you did take this approach then you would need to write accessor methods to increment/decrement the counter as people login/logout -- that is, your authentication system would have to call these accessors. This doesn't sound very good to me (doesn't smell so good eather.) You'll probably be better off looking for some object in your system that would know about these things, something where this kind of responsibility is in line with its responsibilities. There is likely something in your authentication system that would be the right place for this. If so, then where you have @@vara in Play::Application you ask the authentication system to tell you how many are currently logged in. Maybe something in your user management system? Cheers, Bob > -- > Posted via http://www.ruby-forum.com/. > ---- Bob Hutchison Recursive Design Inc. http://www.recursive.ca/ weblog: http://xampl.com/so