I am performing a model search using a region. This is accessed by the search form with the search parameter q. I currently have the code below that is great for searching tags related to the model. But I would also like to find the title field. If I add to this area, then I will get all the results where there is a tag and title that match the search query.
However, I need to return results matching the company_id and category_id files, and / or matching headers or tags. I am stuck on how to add an OR clause to this area.
def self.get_all_products(company, category = nil, subcategory = nil, q = nil)
scope = scoped{}
scope = scope.where "company_id = ?", company
scope = scope.where "category_id = ?", category unless category.blank?
scope = scope.tagged_with(q) unless q.blank?
scope
end
I am using Rails 3.
source
share