2012-01-20 2 views
1

私は多様なlikesモデルを持っています。このクエリを一掃する方法はありますか?Railsの多型的なアロケーションでのクエリのDRYup

user.likes.where(:likeable_id => thing.id, :likeable_type => thing.class) 

これは動作しません:

クラスと同様に ...

# scope 
def self.for(object) 
    scoped.where(:likeable_id => object.id, :likeable_type => object.class.to_s) 
end 

終わります。次に使用する

:これについて

user.likes.where(:likeable => thing) 

答えて

3

方法を私このようにしてください:

user.likes.for(thing) 
関連する問題