ruby on rails - How do I match all "and" using ActiveRecord? -


i need activerecord query match items in params[] array.

my current method gives results based on finding of tags, not "match all"

class product < activerecord::base     has_many :tags      def self.filter_by_params(params)         scoped = self.scoped         scoped = scoped.includes(:tags).where(:tags => {:id => params[:t]}) if params[:t]         scoped     end end 

i attempting write below, gives me no results. can can set me in right direction? there way " , "?

def self.filter_by_params(params)     scoped = self.scoped.includes(:tags)     params[:t].each |t|         scoped = scoped.where(:tags => {:id => t})     end     scoped end 

if understand right params[:t] array of ids. if that's case can do:

def self.filter_by_params(params)   scoped = self.scoped   scoped = scoped.tags.find_all_by_id(params[:t])   scoped end 

or just:

def self.filter_by_params(params)   tags.find_all_by_id(params[:t]) end 

Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -