User has more than 20 records in a table. I only want to keep开发者_如何学Python the last 10 entries. Which means I want to delete the rest.
I want to do this for each user in that table as well.
How should I go about this?
Item.destroy(Item.order('created_at').all.last(10).map(&:id))
There's probably a less expensive way to do it, but that should work for you.
精彩评论