Act-as-taggable-on tagged_with or_where?

I am trying to query OR WHERE in an act-as-taggable-on request, for example ...

Business.tagged_with(params[:query], :any => true) 

But I would also like to execute at the same time or_where, like this ...

 Business.tagged_with(params[:query], :any => true).or_where('name LIKE ?', "%#{params[:query]}%") 

This obviously does not work, since the or_where method does not exist, but does anyone know how to do this correctly?

In short, I'm trying to match any tags or company name. Thank you

+4
source share
1 answer

You can use OR two queries together with | the operator is this:

 Business.tagged_with(params[:query], :any => true) | Business.where('name LIKE ?', "%#{params[:query]}%") 

Please note that this will lead to the loading of results, so after that you will not be able to apply additional conditions, for example, to arrange. It will return an array with all the relevant results in it, excluding duplicates.

+3
source

All Articles