在 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 模型和参数?
最佳答案
正确的语法是:
namespace :foo do
task :bar, [:arg1] => :environment do |t, args|
puts args[:arg1]
end
end
关于ruby-on-rails - 如何在 rake 任务中使用 ActiveRecord 模型和参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24342328/