instance method
second_to_last
Ruby on Rails 8.0.4
Since v5.2.8.1Signature
second_to_last()
Find the second-to-last record. If no order is defined it will order by primary key.
Person.second_to_last # returns the second-to-last object fetched by SELECT * FROM people Person.offset(3).second_to_last # returns the second-to-last object from OFFSET 3 Person.where(["user_name = :u", { u: user_name }]).second_to_last
Source
# File activerecord/lib/active_record/relation/finder_methods.rb, line 319
def second_to_last
find_nth_from_last 2
end
Defined in activerecord/lib/active_record/relation/finder_methods.rb line 319
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActiveRecord::FinderMethods