Module: Ransack::Adapters::ActiveRecord::Base

Defined in:
lib/ransack/adapters/active_record/base.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(base) ⇒ Object



6
7
8
9
10
11
12
# File 'lib/ransack/adapters/active_record/base.rb', line 6

def self.extended(base)
  alias :search :ransack unless base.respond_to? :search
  base.class_eval do
    class_attribute :_ransackers
    self._ransackers ||= {}
  end
end

Instance Method Details

#ransack(params = {}, options = {}) ⇒ Object



14
15
16
17
# File 'lib/ransack/adapters/active_record/base.rb', line 14

def ransack(params = {}, options = {})
  Search.new(self, params ? params.delete_if {
    |k, v| v.blank? && v != false } : params, options)
end

#ransackable_associations(auth_object = nil) ⇒ Object



34
35
36
# File 'lib/ransack/adapters/active_record/base.rb', line 34

def ransackable_associations(auth_object = nil)
  reflect_on_all_associations.map { |a| a.name.to_s }
end

#ransackable_attributes(auth_object = nil) ⇒ Object



24
25
26
# File 'lib/ransack/adapters/active_record/base.rb', line 24

def ransackable_attributes(auth_object = nil)
  column_names + _ransackers.keys
end

#ransacker(name, opts = {}, &block) ⇒ Object



19
20
21
22
# File 'lib/ransack/adapters/active_record/base.rb', line 19

def ransacker(name, opts = {}, &block)
  self._ransackers = _ransackers.merge name.to_s => Ransacker
    .new(self, name, opts, &block)
end

#ransortable_attributes(auth_object = nil) ⇒ Object



28
29
30
31
32
# File 'lib/ransack/adapters/active_record/base.rb', line 28

def ransortable_attributes(auth_object = nil)
  # Here so users can overwrite the attributes
  # that show up in the sort_select
  ransackable_attributes(auth_object)
end