Re: acts_as_taggableのfindメソッド化、その2
それならば,find の option を 第3引数に取って(ラッパーを書いたりでもいいんですが),下のようにすると簡単かも.
def find_tagged_with(taglist, options = {}, find_options = {}) with_scope(:find => find_options) do # : 以下 http://d.hatena.ne.jp/holysugar/20060906/p1 と同じ end end
これでたとえば次のように書けるはず.
Bookmarks.find_tagged_with(tag, {}, :conditions => { :date => Date.today }, :limit => 10, :order => "created_at DESC" )
find_by_sqlを使わないことの何がうれしいかというと with_scope が通るという一点にある.
と書いたのはこのように外部から別の条件を(with_scopeで)加えられる点についてですね.with_scopeはfind_tagged_withの外で使うことも可能ですから.