干掉经常发现的东西
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了干掉经常发现的东西相关的知识,希望对你有一定的参考价值。
# 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.
以上是关于干掉经常发现的东西的主要内容,如果未能解决你的问题,请参考以下文章