Created
July 14, 2014 01:22
-
-
Save alexvbush/4301344b1a94e0d7ab05 to your computer and use it in GitHub Desktop.
Articles Search mixin.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module ArticlesSearch | |
def articles_search(search_criteria, state = nil) | |
@articles = Article.includes(:categories).where('title LIKE ? OR categories.name LIKE ?', "%#{search_criteria}%", "%#{search_criteria}%") | |
if state | |
@articles = @articles.where(state: state) | |
end | |
@articles | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment