Skip to content

Instantly share code, notes, and snippets.

@voising
Last active November 14, 2019 09:41
Show Gist options
  • Save voising/f599a71fe446c628c3afc42a0cd9b8cc to your computer and use it in GitHub Desktop.
Save voising/f599a71fe446c628c3afc42a0cd9b8cc to your computer and use it in GitHub Desktop.
Marketplace - Search by rate & tags - Controller
# frozen_string_literal: true
class ProductsController < ApplicationController
# GET /products
def index
📗𝟮𝟬𝟬 ProductSerializer.new(filtered_products)
end
private
def filtered_products
query = Product.index
# RATE
query = query.filter_on_rate(params[:rate]) if params[:rate]
kinds = params.keys & Tag.kinds.keys
return query unless kinds.any?
# TAGS
query.filter_on_tags(kinds, params)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment