[Rails] Re: Using Initializers

2009-10-20 Thread Marnen Laibow-Koser

Doug Jolley wrote:
> Thanks to all who responded to my inquiry.
> 
> This appears to be a rather basic issue that, for whatever reason,
> doesn't seem to get much attention.
> 
> I've reviewed everything.  My conclusion is that, for my purposes, the
> very basic first approach of just declaring the single needed global
> constant in a file added to the initializers directory is enough to
> meet my needs.

I hope you don't mean "global" as in "Ruby global with a dollar sign". 
If so, that's asking for trouble.  Please see Railscast #85 for a simple 
way of doing this right.

> 
> Again, thanks to all for the input.
> 
>... doug

Best,
--
Marnen Laibow-Koser
http://www.marnen.org
mar...@marnen.org
-- 
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@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~--~~~~--~~--~--~---



[Rails] Re: Using Initializers

2009-10-20 Thread doug

Thanks to all who responded to my inquiry.

This appears to be a rather basic issue that, for whatever reason,
doesn't seem to get much attention.

I've reviewed everything.  My conclusion is that, for my purposes, the
very basic first approach of just declaring the single needed global
constant in a file added to the initializers directory is enough to
meet my needs.

Again, thanks to all for the input.

   ... doug

--~--~-~--~~~---~--~~
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@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~--~~~~--~~--~--~---



[Rails] Re: Using Initializers

2009-10-19 Thread Freddy Andersen

I have another example that I have used for a while...

/config/settings.yml
all: &all_environment_settings
  constant_for_all: somethinf

development: &non_production_settings
<<: *all_environment_settings
something_different_for_dev: dev stuff

Then you can load this file in a initializer:

/initializers/settings.rb
SETTINGS = YAML.load_file("#{RAILS_ROOT}/config/settings.yml")
[RAILS_ENV].symbolize_keys

Now you can call this through SETTINGS[:constant_for_all]

Both methods will work but if you have requirements for the constants
to change between environments then this would be better...
--~--~-~--~~~---~--~~
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@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~--~~~~--~~--~--~---



[Rails] Re: Using Initializers

2009-10-19 Thread doug

Interesting.  The procedure that you describe is much different than
what I expected.  So, I guess that I'm not surprised that what I did
failed to work.  Thanks.  I'll give it a try.

  ... doug

--~--~-~--~~~---~--~~
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@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~--~~~~--~~--~--~---



[Rails] Re: Using Initializers

2009-10-18 Thread Sijo k g

Hi Doug Jolley

 You can create a file like global_constants.rb in initializers 
folder and declare all the global there ..
  Or
Inside this same file create like

module GlobalConstant
  Constantname = value
end

GlobalConstant.freeze

 And access it like GlobalConstant::Constantname

The second one I have not tried.But thinking that it will work



Sijo K George
-- 
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@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~--~~~~--~~--~--~---