I'm stuck on a simple issue here. I'm building an application that manages a database of coupons, each of which has an expiration date. I'm trying to build a rake task that will delete the expired coupons. The relevant code from the rakefile looks like this:
desc "Deletes expired offers from the database."
task :purge_expired => :environment do
today = Date.today.to_s
Offer.where('expires_on < ?', today).destroy
end
That however fails with the following error message:
rake aborted!
wrong number of arguments (0 for 1)
I'm just not sure why. What arguments would be needed?
As an experiment, I found that this worked fine:
desc "Deletes expired offers from the database."
task :purge_expired => :environment do
today = Date.today.to_s
puts Offer.where('expires_on < ?', today).count
end
That returned the right number of records, so I assume I'm successfully gathering up the right objects.
FWIW, I tried this too, and had no luck:
desc "Deletes expired offers from the database."
task :purge_expired => :environment do
today = Date.today.to_s
@offers = Offer.where('expires_on < ?', today)
@offers.destroy
end
So I'm kind of out of ideas. What am I doing wrong here?
Thanks so much for your help. I'm pretty sure I wouldn't have a job if it weren't for Stack Overflow!