【发布时间】:2012-03-28 13:58:38
【问题描述】:
我看过其他帖子,但我仍然遇到问题。下面是我的代码。我有几个 rake 任务,我传入零个、一个甚至五个参数。我错过了什么?
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
我正在使用以下命令运行任务:
$ rake my_namespace:show_user_accounts customer_id=110
错误:
rake aborted!
Couldn't find Customer with id=0
【问题讨论】:
-
@ScottJShea,不是真的。这是我修改后的语法的基础,我不明白为什么它不起作用。 :(
标签: ruby-on-rails rake