To explain this issue I wrote the following rake task
namespace :tutorial do
desc 'tutorial'
task :env =>:environment do
puts "RAILS_ENV: #{RAILS_ENV}"
puts "RAILS_ENV_PRODUCTION: #{RAILS_ENV_PRODUCTION}"
puts "RAILS_ENV_TEST: #{RAILS_ENV_TEST}"
end
end
When I run the following commands:
rake tutorial:env
it will return
RAILS_ENV: development
RAILS_ENV_PRODUCTION: true
RAILS_ENV_TEST: false
I find it strange that RAILS_ENV_PRODUCTION is true, while RAILS_ENV is DEVELOPMENT (I assume development is the preferred default value for most Rake tasks.)
The following commands give expected results
rake tutorial:env RAILS_ENV=development
RAILS_ENV: development
RAILS_ENV_PRODUCTION: false
RAILS_ENV_TEST: false
rake tutorial:env RAILS_ENV=production
RAILS_ENV: production
RAILS_ENV_PRODUCTION: true
RAILS_ENV_TEST: false
Can someone please explain the strange result of the first rake command without the RAILS_ENV being set.
I use Ruby 1.8.7 Rails 2.1.0 OS: Mac OS X 10.6.4
Thanks.