我正在使用 Ruby 2.3.1p112 和 Rails 4.2.7.1 进行编码,并在尝试在其中一个 rake 文件中使用 if 语句时遇到此错误(?)。
我称这个 rake 任务为:
task :bar, [:argument] => :environment do |_task, arg|
binding.pry
if arg.blank?
# do stuff
else
# do other stuff
end
end
来自该工作人员:
# ...
def perform(location = nil)
Rake::Task["foo:bar"].execute(location)
end
# ...
这确实是一个错误还是我缺乏一些基本知识? 谢谢!
最佳答案
你想要
arg[:argument].blank?
因为 arg
是带有 :argument
键的哈希值。
旁注:以下是任务的更具描述性的定义(注意复数 args
和 location
因为它看起来像是您正在传递位置):
task :bar, [:location] => :environment do |_task, args|
if args[:location].blank?
# do stuff
else
# do other stuff
end
end
关于ruby-on-rails - 将参数传递给 rake 任务时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52172080/