[英]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? 如果我在
application.yml
文件中设置了一些环境变量,有没有办法在rake任务中访问它们? Doing env['VARIABLE_NAME']
doesn't work and neither does Rails.env['VARIABLE_NAME']
执行
env['VARIABLE_NAME']
不起作用, 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
: 刚试过这个,它适用于
ENV
:
task :temp => :environment do
puts ENV['i']
end
% rake temp i=5
5
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.