# Where to place and initialize application params

**URL:** <https://www.ruby-forum.com/t/where-to-place-and-initialize-application-params/77029>\
**Category:** Rails\
**Created:** [November 23, 2006, 3:18pm UTC](https://www.ruby-forum.com/t/where-to-place-and-initialize-application-params/77029 "2006-11-23T15:18:18Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![caefer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e36b37/32.png) [@caefer](https://www.ruby-forum.com/u/caefer)\
**Post date:** [November 23, 2006, 3:18pm UTC](https://www.ruby-forum.com/t/where-to-place-and-initialize-application-params/77029/1 "2006-11-23T15:18:18Z")

</div>

Hi folks,

the first places I can think of are environment.rb and application.rb. I  
just wonder if these files should be used to configure the rails  
environment or plugins/engines.

If the common way is to do it with environment.rb and application.rb my  
next question is: how do I access a simple param in environment.rb like  
"application\_name = “My fency rails app” in my application.rb?

Thanks & Regards,

Christian

---

<div class="post-metadata">

**Author:** ![caefer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e36b37/32.png) [@caefer](https://www.ruby-forum.com/u/caefer)\
**Post date:** [November 23, 2006, 3:19pm UTC](https://www.ruby-forum.com/t/where-to-place-and-initialize-application-params/77029/2 "2006-11-23T15:19:46Z")

</div>

Christian S. wrote:

> the first places I can think of are environment.rb and application.rb. I  
> just wonder if these files should be used to configure the rails  
> environment or plugins/engines.
> 
> If the common way is to do it with environment.rb and application.rb my  
> next question is: how do I access a simple param in environment.rb like  
> "application\_name = “My fency rails app” in my application.rb?

Hmmm, just a thought: Could it be done with YAML, maybe?

Christian

---

<div class="post-metadata">

**Author:** ![caefer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e36b37/32.png) [@caefer](https://www.ruby-forum.com/u/caefer)\
**Post date:** [November 23, 2006, 4:33pm UTC](https://www.ruby-forum.com/t/where-to-place-and-initialize-application-params/77029/3 "2006-11-23T16:33:11Z")

</div>

> > "application\_name = “My fency rails app” in my application.rb?
> 
> Hmmm, just a thought: Could it be done with YAML, maybe?

Have a look at this:

[http://www.realityforge.org/articles/2006/02/28/flexible-application-](http://www.realityforge.org/articles/2006/02/28/flexible-application-)  
configuration-in-rails

Regards,  
Andy S.

---

<div class="post-metadata">

**Author:** ![caefer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e36b37/32.png) [@caefer](https://www.ruby-forum.com/u/caefer)\
**Post date:** [November 23, 2006, 3:30pm UTC](https://www.ruby-forum.com/t/where-to-place-and-initialize-application-params/77029/4 "2006-11-23T15:30:05Z")

</div>

In general, environment.rb _is_ the place where you should perform  
configuration. There’s even a comment at the bottom of the file to  
that effect 🙂

You need to consider what it is that you’re actually configuring. If  
it’s some string which acts as the application title, you could place  
this in a constant:

[environment.rb, at the end]

ApplicationName = “I Caught You A Delicious Bass”

and then reference this constant somewhere else. In your example,  
because ‘application\_name’ doesn’t start with a capital letter, Ruby  
assumes that it is a local variable and it is almost certainly lost  
within the scope of your ApplicationController (the class defined in  
application.rb).

In a nutshell, use constants if you want to set some value that needs  
to persist in a different part of Rails. You could even define these  
within a module to keep the top-level namespace clear.

On 11/23/06, Christian S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Hmmm, just a thought: Could it be done with YAML, maybe?
> 
> Christian
> 
> –  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
> 
> >

–

- J \*  
~

---

<div class="post-metadata">

**Author:** ![caefer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e36b37/32.png) [@caefer](https://www.ruby-forum.com/u/caefer)\
**Post date:** [November 23, 2006, 4:51pm UTC](https://www.ruby-forum.com/t/where-to-place-and-initialize-application-params/77029/5 "2006-11-23T16:51:37Z")

</div>

Andrew S. wrote:

> > > "application\_name = “My fency rails app” in my application.rb?
> > 
> > Hmmm, just a thought: Could it be done with YAML, maybe?
> 
> Have a look at this:
> 
> [http://www.realityforge.org/articles/2006/02/28/flexible-application-](http://www.realityforge.org/articles/2006/02/28/flexible-application-)  
> configuration-in-rails

That looks nice! Thank you, IÂ´ll give it a try.

Christian
