Where to place and initialize application params

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

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

"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-
configuration-in-rails

Regards,
Andy S.

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 :slight_smile:

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. [email protected]
wrote:

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

Christian


Posted via http://www.ruby-forum.com/.

  • J *
    ~

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-
configuration-in-rails

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

Christian