i have a page with filters and it doesn't work properly, it works if all filters are set. But if category filter isn't set and the other two are set it wont work(it shows all products). the same as before if category is set and the price is not stock is set again , it shows thing filtered only by category. my model is product.rb
def self.categorized(category=nil)
return self.where("category_id LIKE ?",category ) if category
self
end
def self.priced(price=nil)
return self.where("price < 50") if price=="low"
return self.where("price < 100 and price > 50") if price=="mid"
return self.where("price > 100") if price=="high"
self
end
def self.stocked(stock=nil)
return self.where("stock > 0") if stock=="available"
return self.where("stock = 0" ) if stock=="out"
self
end
def self.catalog(params)
page = params[:page]
category = params[:category]
stock = params[:stock]
price = params[:price]
self.stocked(stock).priced(price).categorized(category)
.paginate(:page =>page).limit(9)
end