I want to limit the number of records a table can hold in rails. If I have a notifications table, how can I make it work to hold only 50 records at a time. So, if a new record is added the first one is deleted and the new one is saved as the 50th.
Is there any cool rails method to do this automatically or do I have to implement it manually in my model when I'm creating a new notification?
I think it's quite simple to implement on own.
Notification.first.destroy if Notification.count > 50
use it in after_commit
callback or whatever cb is best
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With