ActiveRecord::Base.find :last
At last! The latest Ruby on Rails changeset has something I’ve always missed.. find :last.
This new functionality adds a whole lot logic for me. For example
Find the last inserted client
Client.find(:last)
Find the last edited subject
Subject.find(:last, :order => 'modified_at')
This is a lot more readable then
Subject.find(:first, :order => 'modified_at DESC')
The last code makes me interpret the result of the order, I don’t immediately see what I’m requesting, with the last example I immediatly see I’m taking the last modified subject.
Great stuff! This is the reason I’m on Rails Edge
0 comments