task :some_task, :environment do |t, args|
puts Rails.env #=> development, production, etc
puts ENV #=> {}
end
I set some environment variables (either via a local .env, or via Heroku Config via Herokusan), such as which AWS bucket to use, and I want to reference them in the rake task, but ENV is an empty hash. I know something related to environment gets done because of the :environment
task dependency and that Rails.env
has a value, but I'm not clear on the details.
So, how can I use ENV
in a Rake task?
$ rake some_task
in the app directory. Some ofENV
is in.env
, and I may need to do$ foreman run rake task
for the Heroku stuff. – Manila$ foreman run rake some_task
is the correct answer – Kelcey