How to find the number of Books updated by the program in Rails

zawhtutwin

Zaw Htut Win

Posted on September 22, 2022

How to find the number of Books updated by the program in Rails

Let's say I have a script running and I want to find the last updated isbn number of the book during the run time with rails console.

Book.where(updated_at:Book.maximum('updated_at')).first.isbn
Enter fullscreen mode Exit fullscreen mode

Then I can find how many books are updated during the runtime with this enhanced query

Book.pluck('isbn').uniq.find_index(Book.where(updated_at:Book.maximum('updated_at')).first.isbn)+1
Enter fullscreen mode Exit fullscreen mode

Neat! Isn't it ?

💖 💪 🙅 🚩
zawhtutwin
Zaw Htut Win

Posted on September 22, 2022

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related