Revision: 2366
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at February 4, 2007 15:20 by gnatware
Initial Code
# Always be on the lookout for duplicated code. If you find yourself doing
# asset.incomings.find(:all, :limit => 10) in multiple places, then perhaps you need to
# pull that into a method of its own. Given the use of the magic number "10", it might
# not be a bad idea to do so anyway.
class Asset < ActiveRecord::Base
has_many :incomings do
def recent(count=10)
find(:all, :limit => count)
end
end
end
# Then, you just have to do @asset.incomings.recent to get the first 10 items.
Initial URL
http://www.therailsway.com/2007/1/10/assetsgraphed-part-2
Initial Description
Initial Title
DRY up frequent finds
Initial Tags
find
Initial Language
Ruby