Created
December 27, 2017 13:59
-
-
Save vanakenm/88dbda94b5dc32874f95deba15b3430d to your computer and use it in GitHub Desktop.
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
class EffinQuote < ApplicationRecord | |
include PgSearch | |
pg_search_scope :search_by_word, against: [:contents] | |
def self.find_by_word(word) | |
complete.search_by_word(word).first | |
end | |
def self.find_or_random(text) | |
quote = EffinQuote.find_by_word(text) | |
quote ? [quote, false] : [EffinQuote.complete.sample, true] | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment