Rake 任务环境变量 w/Command 行参数
Rake Task environment variable w/Command Line Arguments
所以我在我的 rake 任务中得到了一些 "Uninitalized constants",我做了一些谷歌搜索,发现需要加载环境变量。但是我也使用命令行参数,我不确定是否定位是否正确或什么:
desc "Wipes Specific User"
task :clean_user => environment [:user] do |t, args|
puts "Running clean_user for #{args[:user]}..."
Core::Stuff.find(args[:user]).wipe_user
end
如果没有某个地方的环境变量,我会抱怨 Core::Stuff 未初始化,但我试图通过 CL 传递 :user。 (这只是确保一切正常的抽样任务)。
我是不是漏掉了什么?
编辑:修复问题:
task :clean_user, [:user] => :environment
但是现在它似乎正在将我的 PATH 加载到参数中(我收到一个错误抱怨如何 "Core::Stuff cannot find a user id with id of "" 。所以它就像使用我的 CL 路径作为 ID?
gem 中的文档指定:
task task_name, arguments => dependencies
这意味着您的代码需要:
task :clean_user, [:user] => :environment do |t, args|
所以我在我的 rake 任务中得到了一些 "Uninitalized constants",我做了一些谷歌搜索,发现需要加载环境变量。但是我也使用命令行参数,我不确定是否定位是否正确或什么:
desc "Wipes Specific User"
task :clean_user => environment [:user] do |t, args|
puts "Running clean_user for #{args[:user]}..."
Core::Stuff.find(args[:user]).wipe_user
end
如果没有某个地方的环境变量,我会抱怨 Core::Stuff 未初始化,但我试图通过 CL 传递 :user。 (这只是确保一切正常的抽样任务)。
我是不是漏掉了什么?
编辑:修复问题:
task :clean_user, [:user] => :environment
但是现在它似乎正在将我的 PATH 加载到参数中(我收到一个错误抱怨如何 "Core::Stuff cannot find a user id with id of "" 。所以它就像使用我的 CL 路径作为 ID?
gem 中的文档指定:
task task_name, arguments => dependencies
这意味着您的代码需要:
task :clean_user, [:user] => :environment do |t, args|