DEV Community

Cover image for How to find the number of Books updated by the program in Rails
Zaw Htut Win
Zaw Htut Win

Posted on

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 ?

Top comments (0)