Re: Is there an Application state in Rails like ASP

s.ross
Thu, 26 Oct 2006 23:42:12 -0000

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/.
>
> >