# Environment.rb usage? use of "Rails::Initializer.run" sectio

**URL:** <https://www.ruby-forum.com/t/environment-rb-usage-use-of-rails-initializer-run-sectio/108294>\
**Category:** Rails\
**Created:** [July 1, 2007, 11:12pm UTC](https://www.ruby-forum.com/t/environment-rb-usage-use-of-rails-initializer-run-sectio/108294 "2007-07-01T23:12:19Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![greg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/71c47a/32.png) [@greg](https://www.ruby-forum.com/u/greg)\
**Post date:** [July 1, 2007, 11:12pm UTC](https://www.ruby-forum.com/t/environment-rb-usage-use-of-rails-initializer-run-sectio/108294/1 "2007-07-01T23:12:19Z")

</div>

Hi,

Can anyone explain the intended usage within “environment.rb” of the  
areas  
(a) within the "Rails::Initializer.run do |config| " block section and  
(b)  
the area after this block.

For example when/what do I include in the "Rails::Initializer.run do  
|config| " section versus not? As an example say setting up constants.

Tks

---

<div class="post-metadata">

**Author:** ![greg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/71c47a/32.png) [@greg](https://www.ruby-forum.com/u/greg)\
**Post date:** [July 4, 2007, 4:51pm UTC](https://www.ruby-forum.com/t/environment-rb-usage-use-of-rails-initializer-run-sectio/108294/2 "2007-07-04T16:51:22Z")

</div>

Greg H. wrote:

> >

Have a look at  
[http://glu.ttono.us/articles/2006/05/22/configuring-rails-environments-the-cheat-sheet](http://glu.ttono.us/articles/2006/05/22/configuring-rails-environments-the-cheat-sheet)  
and  
[http://glu.ttono.us/articles/2006/05/22/guide-environments-in-rails-1-1](http://glu.ttono.us/articles/2006/05/22/guide-environments-in-rails-1-1)  
Hope this helps  
Chris

## –

Autopendium :: Stuff about old cars  
[http://autopendium.com](http://autopendium.com)

---

<div class="post-metadata">

**Author:** ![greg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/71c47a/32.png) [@greg](https://www.ruby-forum.com/u/greg)\
**Post date:** [July 6, 2007, 8:34am UTC](https://www.ruby-forum.com/t/environment-rb-usage-use-of-rails-initializer-run-sectio/108294/3 "2007-07-06T08:34:24Z")

</div>

thanks Chris,

It still didn’t fully clarify things for me however. I see they state:  
“With the exceptions of the RAILS\_GEM\_VERSION constant and the setting  
for  
what environment to use, the bulk of the configuration in Rails happens  
within the Rails::Initializer.run block.”

However I note that in my application I am currently (writely or  
wrongly)  
been setting various parameters outside the "Rails::Initializer.run do  
|config| " block…, e.g.

- LOCALES = {‘en’ =\> ‘en’, ‘fr’ =\> ‘fr’}.freeze
- ActionMailer::Base.smtp\_settings = { etc
- ExceptionNotifier.email\_prefix = “xxx” etc
- TimeZone.all.each\_with\_index { |tz, i| $TIME\_ZONE\_ARRAY \<\< [tz,  
i.to\_s] }
- class Logger  
def format\_message(severity, timestamp, progname, msg) etc

So it’s still not quite clear to me whether I’m currently following  
rails  
best practice or not? Any advice anyone?

Tks  
Greg

---

<div class="post-metadata">

**Author:** ![greg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/71c47a/32.png) [@greg](https://www.ruby-forum.com/u/greg)\
**Post date:** [July 6, 2007, 9:39am UTC](https://www.ruby-forum.com/t/environment-rb-usage-use-of-rails-initializer-run-sectio/108294/4 "2007-07-06T09:39:32Z")

</div>

I set up all my constants, including ActionMailer settings, after the  
Rails::Initializer.run block, and I believe this is the correct way to  
do it. Apart from anything else, I don’t think they don’t require access  
to the config object which is passed to the block.

Cheers  
Chris

Greg H. wrote:

> ```
> > Hi,
> > Tks
> --
> ----------------------------
> Autopendium :: Stuff about old cars
> http://autopendium.com
> 
> ```
> 
> >

## –

Autopendium :: Stuff about old cars  
[http://autopendium.com](http://autopendium.com)
