[英]How to use in rake task ActiveRecord model and argument
In a rake task I'm using argument like this: 在rake任务中,我使用的参数是这样的:
namespace :foo do
task :bar, [:arg1] do |t, args|
puts args[:arg1]
end
end
And I want to use ActiveRecord model, I add => :environment
like this: 我想使用ActiveRecord模型,我添加
=> :environment
像这样:
namespace :foo do
task :bar => :environment, [:arg1] do |t, args|
puts args[:arg1]
end
end
And when I run rake foo:bar[1]
, it ends up with error: 并且当我运行
rake foo:bar[1]
,它以错误结束:
rake aborted!
SyntaxError: /home/ironsand/rails_project/lib/tasks/foo.rake:2: syntax error, unexpected keyword_do_block, expecting =>
task :bar => :environment, [:arg1] do |t, args|
What should I to use ActiveRecord model and argument same time in a rake task? 我应该在rake任务中同时使用ActiveRecord模型和参数吗?
Correct syntax is: 正确的语法是:
namespace :foo do
task :bar, [:arg1] => :environment do |t, args|
puts args[:arg1]
end
end
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.