Before Rails 2.x the preferred way to get the current environment was using the RAILS_ENV
constant. Likewise, you can use RAILS_DEFAULT_LOGGER
to get the current logger or RAILS_ROOT
to get the path to the root folder.
Starting from Rails 2.x, Rails introduced the Rails
module with some special methods:
This isn't just a cosmetic change. The Rails module offers capabilities not available using the standard constants such as StringInquirer
support.
There are also some slight differences. Rails.root
doesn't return a simple String
buth a Path
instance.
Anyway, the preferred way is using the Rails
module. Constants are deprecated in Rails 3 and will be removed in a future release, perhaps Rails 3.1.