Module: Searchable::ActiveRecord::InstanceMethods

Defined in:
lib/searchable.rb

Instance Method Summary collapse

Instance Method Details

#search(options = {}) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/searchable.rb', line 11

def search(options = {})
  case search_method(options)
  when :string
    self.where(["#{@field} LIKE ?", "%#{options[:by]}%"])
  when :letter
    self.where(["#{@field} LIKE ?", "#{options[:by_letter]}%"])
  when :numbers
    self.where(["#{@field} RLIKE ?", '^[0-9]'])
  else
    self.where(1)
  end
end