In classic ASP I can use the Application object to persist application wide values. Is there something similar built into Rails? I''m already aware of things like memcache. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Unless I''m mistaken, anything you create in environment.rb persists until server restart because environment.rb is a load-once file. There are several plugins for storing settings (n/v pairs), but if you want to persist page state like WinForms on Asp.Net, this isn''t the method for you. If you''re casting about for a way to store options and don''t want to go the plugin route, stick this in RAILS_ROOT/lib and they you can write code like: Options[:email_recipients] = [''me-3Q2Tfjf0mexWk0Htik3J/w@public.gmane.org'', ''you-FBj3rGVNSac4Q++5jOxPmw@public.gmane.org''] # options.rb # # Provide a container for global option storage # Both getter/setter and [] access methods are # provided. class Options @@option_hash = {} def self.set(option_name, value) option_name = option_name.to_s @@option_hash[option_name] = value end def self.get(option_name) option_name = option_name.to_s @@option_hash[option_name] end def self.[]=(option_name, value) option_name = option_name.to_s self.set(option_name, value) end def self.[](option_name) option_name = option_name.to_s self.get(option_name) end def self.has_key?(key) key = key.to_s @@option_hash.has_key?(key) end def self.key?(key) self.has_key?(key) end end On Oct 26, 2006, at 12:35 PM, Kelly Oppenheinmer wrote:> > In classic ASP I can use the Application object to persist application > wide values. Is there something similar built into Rails? I''m > already > aware of things like memcache. > > -- > Posted via http://www.ruby-forum.com/. > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Ezra Zygmuntowicz
2006-Oct-27 00:31 UTC
Re: Is there an Application state in Rails like ASP
Hi~ On Oct 26, 2006, at 4:42 PM, s.ross wrote:> > Unless I''m mistaken, anything you create in environment.rb persists > until server restart because environment.rb is a load-once file. > There are several plugins for storing settings (n/v pairs), but if > you want to persist page state like WinForms on Asp.Net, this isn''t > the method for you. > > If you''re casting about for a way to store options and don''t want to > go the plugin route, stick this in RAILS_ROOT/lib and they you can > write code like: > > Options[:email_recipients] = [''me-3Q2Tfjf0mexWk0Htik3J/w@public.gmane.org'', ''you-FBj3rGVNSac4Q++5jOxPmw@public.gmane.org''] > > # options.rb > # > # Provide a container for global option storage > # Both getter/setter and [] access methods are > # provided. > > class Options > @@option_hash = {} > > def self.set(option_name, value) > option_name = option_name.to_s > @@option_hash[option_name] = value > end > > def self.get(option_name) > option_name = option_name.to_s > @@option_hash[option_name] > end > > def self.[]=(option_name, value) > option_name = option_name.to_s > self.set(option_name, value) > end > > def self.[](option_name) > option_name = option_name.to_s > self.get(option_name) > end > > def self.has_key?(key) > key = key.to_s > @@option_hash.has_key?(key) > end > > def self.key?(key) > self.has_key?(key) > end > endKeep in mind this will not work when you run more then one rails backend. As each mongrel or fcgi will have a separate copy of this class and you are not always garaunteed that your users will always hit the same backend. So you will have to use the session, memcached or a DRb server for global state because it needs to be an external process that all rails backends can talk to to keep the data consistent. Or you also use the database to store state too. Cheers- -- Ezra Zygmuntowicz -- Lead Rails Evangelist -- ez-NLltGlunAUd/unjJdyJNww@public.gmane.org -- Engine Yard, Serious Rails Hosting -- (866) 518-YARD (9273) --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Good point. This was lifted from some of my code that uses it on app startup to store app-wide setup info. Of course when each backend is fired up it is stuffed with the same information so ''sall good. Application state can better be preserved using memcached or dRb or even AR-sessions. Just don''t save too much state :) On Oct 26, 2006, at 5:31 PM, Ezra Zygmuntowicz wrote:> > Hi~ > > On Oct 26, 2006, at 4:42 PM, s.ross wrote: > >> >> Unless I''m mistaken, anything you create in environment.rb persists >> until server restart because environment.rb is a load-once file. >> There are several plugins for storing settings (n/v pairs), but if >> you want to persist page state like WinForms on Asp.Net, this isn''t >> the method for you. >> >> If you''re casting about for a way to store options and don''t want to >> go the plugin route, stick this in RAILS_ROOT/lib and they you can >> write code like: >> >> Options[:email_recipients] = [''me-3Q2Tfjf0mexWk0Htik3J/w@public.gmane.org'', >> ''you-FBj3rGVNSac4Q++5jOxPmw@public.gmane.org''] >> >> # options.rb >> # >> # Provide a container for global option storage >> # Both getter/setter and [] access methods are >> # provided. >> >> class Options >> @@option_hash = {} >> >> def self.set(option_name, value) >> option_name = option_name.to_s >> @@option_hash[option_name] = value >> end >> >> def self.get(option_name) >> option_name = option_name.to_s >> @@option_hash[option_name] >> end >> >> def self.[]=(option_name, value) >> option_name = option_name.to_s >> self.set(option_name, value) >> end >> >> def self.[](option_name) >> option_name = option_name.to_s >> self.get(option_name) >> end >> >> def self.has_key?(key) >> key = key.to_s >> @@option_hash.has_key?(key) >> end >> >> def self.key?(key) >> self.has_key?(key) >> end >> end > > > Keep in mind this will not work when you run more then one rails > backend. As each mongrel or fcgi will have a separate copy of this > class and you are not always garaunteed that your users will always > hit the same backend. So you will have to use the session, memcached > or a DRb server for global state because it needs to be an external > process that all rails backends can talk to to keep the data > consistent. Or you also use the database to store state too. > > > Cheers- > > -- Ezra Zygmuntowicz > -- Lead Rails Evangelist > -- ez-NLltGlunAUd/unjJdyJNww@public.gmane.org > -- Engine Yard, Serious Rails Hosting > -- (866) 518-YARD (9273) > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---