With :limit in query, I will get first N records. What is the easiest way to get last N records?
:limit
Just try:
Model.order("field_for_sort desc").limit(5)
we can use Model.last(5) or Model.limit(5).order(id: :desc) in rails 5.2
Model.last(5)
Model.limit(5).order(id: :desc)