在rake任务中,我正在使用这样的论点:
namespace :foo do
task :bar, [:arg1] do |t, args|
puts args[:arg1]
end
end
我想使用ActiveRecord模型,我这样添加=> :environment
:
namespace :foo do
task :bar => :environment, [:arg1] do |t, args|
puts args[:arg1]
end
end
当我运行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|
我应该在rake任务中同时使用ActiveRecord模型和参数?
答案 0 :(得分:2)
正确的语法是:
namespace :foo do
task :bar, [:arg1] => :environment do |t, args|
puts args[:arg1]
end
end