activerecord - how to join named scopes in rails -


i want join named scopes generate them array. how wouldi , can't join named scopes, there better way this?

 scope :search, ->(attrs_for_search,params)    if attrs_for_search.present?      params_to_search_on = params.keys & attrs_for_search      params_to_search_on.collect{|x| where("#{x} ilike ?", "%#{params[x]}%")     }    else                       none                   end                    end      contact.search(%w[email],{'email => 'jason'})   

i think can create scope , use 'send' method join scopes.

scope :search, ->(field, value)    where("#{field} ?", "%#{value}%") end  def self.multi_search(params)     result = nil     params_to_search_on = params.keys     params_to_search_on.each |k|       if result.nil?         result = message.send(:search, k, params[k])       else         result = result.send(:search, k, params[k])       end     end     result end 

hopes you.


Comments

Popular posts from this blog

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

c++ - OpenMP unpredictable overhead -

javascript - Wordpress slider, not displayed 100% width -