What is the best way to create a singleton global hash variable that is shared between controllers in rails? Thank, mr
One way would to be to create a global hash in the application controller, application.rb And then make sure your controllers are defined as: class YourController < ApplicationController you can define common methods here too. -----Original Message----- From: rails-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org [mailto:rails-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] On Behalf Of mr Sent: Sunday, August 21, 2005 10:52 AM To: rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org Subject: [Rails] singleton global hash What is the best way to create a singleton global hash variable that is shared between controllers in rails? Thank, mr _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails -- No virus found in this incoming message. Checked by AVG Anti-Virus. Version: 7.0.338 / Virus Database: 267.10.12/77 - Release Date: 8/18/2005
The ApplicationController only works if you''re processing all requests in one process (i.e. no fastcgi clustering). I don''t know a better option (besides a db table) to get what you''re looking for in the general case. A simple id/key/value sql table with yamlized keys/values would be simple to do. Brian On 8/21/05, francois <francois-VKbYeNyhmt9BDgjK7y7TUQ@public.gmane.org> wrote:> One way would to be to create a global hash in the application > controller, application.rb > And then make sure your controllers are defined as: > class YourController < ApplicationController > > you can define common methods here too. > > -----Original Message----- > From: rails-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > [mailto:rails-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] On Behalf Of mr > Sent: Sunday, August 21, 2005 10:52 AM > To: rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > Subject: [Rails] singleton global hash > > What is the best way to create a singleton global hash variable that is > shared between controllers in rails? > > Thank, > mr > > > > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > > -- > No virus found in this incoming message. > Checked by AVG Anti-Virus. > Version: 7.0.338 / Virus Database: 267.10.12/77 - Release Date: > 8/18/2005 > > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- The years ahead pick up their dark bags. They move closer. There''s a slight rise in the silence then nothing. -- (If you''re receiving this in response to mail sent to bluczkie-OM76b2Iv3yLQjUSlxSEPGw@public.gmane.org, don''t be concerned This is my new address, but mail will be forwarded here indefinitely)
mr wrote:> What is the best way to create a singleton global hash variable that is > shared between controllers in rails?Depending on what you are planning to use it for, such a thing might be a terrible idea. If you explain what you are attempting to do, someone on the list might be able to offer a better solution since they will know more about your situation. Nicholas Seckar Rails Core Developer http://www.catb.org/~esr/faqs/smart-questions.html
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Aug 21, 2005, at 4:52 AM, mr wrote:> What is the best way to create a singleton global hash variable > that is > shared between controllers in rails?If you want to make your own class to handle this, take a look at the Singleton mixin: http://www.ruby-doc.org/core/classes/Singleton.html George - -- George Hotelling GPG: 0x8175D485 ] http://george.hotelling.net ] _ _ _ ___ _ _ _/ -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.1 (Darwin) iD8DBQFDCLnogXVRXIF11IURAkdJAKCxRYhZ4b8/PuAo/Ljo2chI5kdO9QCbB5QL uSq+I/PRtKpEvOE8mkpkyWc=uEim -----END PGP SIGNATURE-----
> On Aug 21, 2005, at 4:52 AM, mr wrote: > > What is the best way to create a singleton global hash variable > > that is > > shared between controllers in rails?How about the following in environment.rb MY_GLOBAL_HASH = {''important''=>''stuff''} Craig Davey