/ Published in: Ruby
- # 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)
- # Then, you just have to do @asset.incomings.recent to get the first 10 items.
You need to login to post a comment.