I have the following query method in my ActiveRecord model:
def self.tagged_with( string )
array = string.split(\',\').map{ |s| s.lstrip }
select(\'disti
This should work:
def self.tagged_with( string )
array = string.split(',').map{ |s| s.lstrip }
select('distinct photos.*').
joins(:tags).
where('tags.name' => array).
group("photos.id").
having("count(*) = #{array.size}")
end
Above will match photos that have tags red and blue at least. So that means if a photo has red, blue and green tags, that photo would match too.