You can use the built-in Rails methods. Note that when using these methods, you need to wrap your request in an array (if you interpolate the variables).
Iterate over each destroy call (which will trigger callbacks, etc.):
User.destroy_all(["clicks_given - clicks_received < ?", -5])
Or just delete them in the database in one query (without iterations for each element), you can do this, but keep in mind that it will not trigger your callbacks:
User.delete_all(["clicks_given - clicks_received < ?", -5])
Dylan markow
source share