[英]How can I read a CSV file as a rake task and instantiate a model class? - getting ActiveRecord connection error
[英]How to use in rake task ActiveRecord model and argument
在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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.