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.method_defined? :search
  base.class_eval do
    class_attribute :_ransackers
    self._ransackers ||= {}
  end
end

Instance Method Details

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



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

def ransack(params = {}, options = {})
  Search.new(self, params, options)
end

#ransackable_associations(auth_object = nil) ⇒ Object



26
27
28
# File 'lib/ransack/adapters/active_record/base.rb', line 26

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

#ransackable_attributes(auth_object = nil) ⇒ Object



22
23
24
# File 'lib/ransack/adapters/active_record/base.rb', line 22

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

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



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

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