Hi, I''m looking for a way to store common settings, such as the application_name or email address from value in a file. I then want to be able to call these settings in my controllers and models? Is there any easy way of doing this? and where would you recommend I save the file ? Thanks scott -- Posted via http://www.ruby-forum.com/.
Put the file in the lib directory and then just require it where you need it. You could also make it a Module which may be loaded for you and then you can just include it. lib/application-info.rb module ApplicationInfo attr_reader :application_name, :application_email @application_name = "My Cool App" @application_email = "cool-kaBaBF+qkVv3oGB3hsPCZA@public.gmane.org" end class SomethingController < AC::Base include ApplicationInfo # now your actions and views have access to # @application_name and @application_email end On 8/3/06, scott <scott-cZLgC0QEtYNiLUuM0BA3LQ@public.gmane.org> wrote:> Hi, > > I''m looking for a way to store common settings, such as the > application_name or email address from value in a file. > > I then want to be able to call these settings in my controllers and > models? > > Is there any easy way of doing this? and where would you recommend I > save the file ? > > Thanks > scott > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
I just stick my common settings into environment.rb, such as: SUPPORT_EMAIL = "support@mydomain.com" then I can use "mail_to(SUPPORT_EMAIL)" inside my app Mike On 8/3/06, Carl Fyffe <carl.fyffe@gmail.com> wrote:> Put the file in the lib directory and then just require it where you > need it. You could also make it a Module which may be loaded for you > and then you can just include it. > > lib/application-info.rb > > module ApplicationInfo > attr_reader :application_name, :application_email > @application_name = "My Cool App" > @application_email = "cool@mycoolapp.com" > end > > class SomethingController < AC::Base > include ApplicationInfo > > # now your actions and views have access to > # @application_name and @application_email > > end > > On 8/3/06, scott <scott@impulseuk.com> wrote: > > Hi, > > > > I''m looking for a way to store common settings, such as the > > application_name or email address from value in a file. > > > > I then want to be able to call these settings in my controllers and > > models? > > > > Is there any easy way of doing this? and where would you recommend I > > save the file ? > > > > Thanks > > scott > > > > -- > > Posted via http://www.ruby-forum.com/. > > _______________________________________________ > > Rails mailing list > > Rails@lists.rubyonrails.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Carl Fyffe wrote:> Put the file in the lib directory and then just require it where you > need it. You could also make it a Module which may be loaded for you > and then you can just include it. > > lib/application-info.rb > > module ApplicationInfo > attr_reader :application_name, :application_email > @application_name = "My Cool App" > @application_email = "cool@mycoolapp.com" > end > > class SomethingController < AC::Base > include ApplicationInfo > > # now your actions and views have access to > # @application_name and @application_email > > endthanks carl, Will give it a go -- Posted via http://www.ruby-forum.com/.
Hi Scott, I would go for something much simpler, in environnment.rb: CONFIG = { :email => ''foo@bar.com'', } Then, calling from everywhere in the app: CONFIG[:email] Jean-Etienne -- Posted via http://www.ruby-forum.com/.
There are numerous plugins for this. Naively I wrote this code that I put in /lib. You can get to it from anywhere and it provides a straightforward array-like interface. E.g., Options[:email_from] = ''theboss@mydomain.com'' Options[:smtp_server] = ''smtp.mydomain.com'' HTH # 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 -- View this message in context: http://www.nabble.com/Store-common-settings-in-one-file--tf2046127.html#a5643220 Sent from the RubyOnRails Users forum at Nabble.com.