Lieven Cardoen
Lieven Cardoen

Reputation: 25959

How to log environment which Rails is running?

I tried using

logger.info "Rails Environment #{RAILS.env}"

but I'm getting an error:

uninitialized constant ApplicationController::RAILS

Upvotes: 0

Views: 137

Answers (1)

prasvin
prasvin

Reputation: 3009

Use Rails.env instead of RAILS.env. So, that would be

logger.info "Rails Environment #{Rails.env}"

Rails interpretes RAILS as a constant. That is why there's an 'uninitialized constant' error.

I remember deprecation warnings when using RAILS_ROOT or RAILS_ENV. Then they got yanked (no idea which version). Now, these are interpreted as constants. So, Rails.root and Rails.env are used instead - new ones are available in both Rails 2 and 3.

May be you confused RAILS.env with RAILS_ENV. But, none of these two function now.

Upvotes: 3

Related Questions