Skip to content

Instantly share code, notes, and snippets.

@vanakenm
Created December 27, 2017 13:59
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 vanakenm/88dbda94b5dc32874f95deba15b3430d to your computer and use it in GitHub Desktop.
Save vanakenm/88dbda94b5dc32874f95deba15b3430d to your computer and use it in GitHub Desktop.
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