/ Published in: Ruby

Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
# 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.
URL: http://www.therailsway.com/2007/1/10/assetsgraphed-part-2
Comments
