I am stuck in a simple problem here. I am creating an application that manages a database of coupons, each of which has an expiration date. I am trying to create a rake task that will remove expired coupons. The corresponding code from the rake file is as follows:
desc "Deletes expired offers from the database." task :purge_expired => :environment do today = Date.today.to_s Offer.where('expires_on < ?', today).destroy end
Something fails with the following error message:
rake aborted! wrong number of arguments (0 for 1)
I just donβt know why. What arguments are needed?
As an experiment, I found this works 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
This returned the correct number of records, so I assume that I am successfully collecting the necessary objects.
FWIW, I tried this too, and I 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 a little out of ideas. What am I doing wrong here?
Many thanks for your help. Iβm sure I wouldnβt have a job if not for Stack Overflow!
source share