简体   繁体   中英

Can you access environment variables in a rake task?

If I set up some environment variables in an application.yml file is there a way to access them inside a rake task? Doing env['VARIABLE_NAME'] doesn't work and neither does Rails.env['VARIABLE_NAME']

My rake task:

task :create_new_assignment => [:environment] do
   puts env['VARIABLE_NAME'] # => fails.
end

Just tested this, it works with ENV :

task :temp => :environment do
  puts ENV['i']
end

% rake temp i=5
5

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM