Skip to content

Instantly share code, notes, and snippets.

@domagude
Last active November 2, 2017 17:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save domagude/6b5dfe52962cb938caf02d529b8cc755 to your computer and use it in GitHub Desktop.
Save domagude/6b5dfe52962cb938caf02d529b8cc755 to your computer and use it in GitHub Desktop.
...
scope :by_category, -> (branch, category_name) do
joins(:category).where(categories: {name: category_name, branch: branch})
end
scope :by_branch, -> (branch) do
joins(:category).where(categories: {branch: branch})
end
scope :search, -> (search) do
where("title ILIKE lower(?) OR content ILIKE lower(?)", "%#{search}%", "%#{search}%")
end
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment