How do I destroy all but the newest n records using Rails\' ActiveRecord?
I can get the newest n records using order and limit but how do I destroy the inverse?
[Rails 5 / ActiveRecord::Relation]
destroy_all no longer takes parameters... Actually, the ActiveRecord::Relation never allowed parameters I don't think... Anyway, you should just put the condition before it, but use destroy_all after the query, like this:
Person.destroy_all("last_login < '2004-04-04'")
Person.destroy_all(status: "inactive")
Person.where(age: 0..18).destroy_all