Reputation: 15181
In a rake task I'm using argument like this:
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:
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 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?
Upvotes: 2
Views: 591
Reputation: 585
Correct syntax is:
namespace :foo do
task :bar, [:arg1] => :environment do |t, args|
puts args[:arg1]
end
end
Upvotes: 3