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
# 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

Ransackable_associations, by default, returns the names of all associations as an array of strings. For overriding with a whitelist array of strings.



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

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

#ransackable_attributes(auth_object = nil) ⇒ Object

Ransackable_attributes, by default, returns all column names and any defined ransackers as an array of strings. For overriding with a whitelist array of strings.



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

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

#ransackable_scopes(auth_object = nil) ⇒ Object

Ransackable_scopes, by default, returns an empty array i.e. no class methods/scopes are authorized. For overriding with a whitelist array of symbols.



51
52
53
# File 'lib/ransack/adapters/active_record/base.rb', line 51

def ransackable_scopes(auth_object = nil)
  []
end

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



18
19
20
21
# 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

#ransortable_attributes(auth_object = nil) ⇒ Object

Ransortable_attributes, by default, returns the names of all attributes available for sorting as an array of strings. For overriding with a whitelist array of strings.



43
44
45
# File 'lib/ransack/adapters/active_record/base.rb', line 43

def ransortable_attributes(auth_object = nil)
  ransackable_attributes(auth_object)
end