1

I need to make a custom Rails 4 rake task to delete all records in database using ip:

task :delete_records, [:ip] => :environment do |t, args|
  User.destroy_all(ip: args.ip)
end

I try to execute it using the following command:

bundle exec rake delete_records["127.0.0.1"] but I've the error:

no matches found: delete_records["127.0.0.1"]

How can I fix it? Thank in advance!

malcoauri
  • 11,904
  • 28
  • 82
  • 137

1 Answers1

0

I'm guessing you used this answer for help - although we've done rake tasks before, we've never used one with arguments like this

--

Test

We've created custom rake tasks before - they reside in lib/tasks

I would test out yours by doing the following:

#lib/tasks/your_task.rake
desc "Remove all records for particular IP"
task :delete_records, [:id] => :environment do
    args.with_defaults(:ip => "127.0.0.1") 
    User.destroy_all ip: args.ip
end

If this does not work, it will mean there's something wrong with the definition of your task (it's not in the correct folder or something)

The above should determine if your argument definition is the issue; if it isn't you should let me know so we can work to fix it

Community
  • 1
  • 1
Richard Peck
  • 76,116
  • 9
  • 93
  • 147