Change to Rake tasks and argument structure in Rails 3.2?
I've seen other posts, but I'm still having problems. Below is my code. I have multiple rake problems where I pass zero, one or even five arguments. What am I missing?
namespace :my_namespace do
desc 'shows user accounts within the database for the specified customer.'
task :show_user_accounts, [:customer_id] => :environment do |t, args|
cust = Customer.find( args.customer_id.to_i )
cust.users.each do |user|
puts "User Name: #{user.name}\tUser ID: #{user.id}\t"
end
end
end
I run the task with the following command:
$ rake my_namespace:show_user_accounts customer_id=110
Mistake:
rake aborted!
Couldn't find Customer with id=0
+3
source to share
1 answer
After a lot of searching, I found that not only the syntax for the rake problem has changed, but the execution syntax as well. So my rake problem code (above) is correct, but my call was wrong.
The correct way to do it on a rake task is:
$ rake my_namespace:show_user_accounts[110]
I found the answer here: http://www.redconfetti.com/2012/01/example-rake-task/
+5
source to share