Created
January 22, 2016 04:44
-
-
Save ScorpiusZ/f4cac4ebfdbaea4540b6 to your computer and use it in GitHub Desktop.
Revisions
-
ScorpiusZ renamed this gist
Jan 22, 2016 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
ScorpiusZ created this gist
Jan 22, 2016 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,25 @@ module Searchable extend ActiveSupport::Concern included do scope :pg_search, ->(keyword){ where(search_query keyword) } include ClassMethods end module ClassMethods def search_against params @search_against ||= params if params.is_a? Array end def search_query keyword @search_against.map{|x| x.to_s + "~* '#{keyword}'"}.join(' or ') end end end class Topic < ActiveRecord::Base include Searchable search_against [:title,:description,:body] end