module RansackUI::Adapters::ActiveRecord::Base

Public Class Methods

extended(base) click to toggle source
# File lib/ransack_ui/adapters/active_record/base.rb, line 5
def self.extended(base)
  base.class_eval do
    class_attribute :_ransackable_associations
    class_attribute :_ransack_can_autocomplete
    self._ransackable_associations ||= []
    self._ransack_can_autocomplete = false
  end
end

Public Instance Methods

has_ransackable_associations(associations) click to toggle source
# File lib/ransack_ui/adapters/active_record/base.rb, line 14
def has_ransackable_associations(associations)
  self._ransackable_associations = associations
end
ransack_can_autocomplete() click to toggle source
# File lib/ransack_ui/adapters/active_record/base.rb, line 18
def ransack_can_autocomplete
  self._ransack_can_autocomplete = true
end
ransackable_associations(auth_object = nil) click to toggle source
# File lib/ransack_ui/adapters/active_record/base.rb, line 29
def ransackable_associations(auth_object = nil)
  all_associations = reflect_on_all_associations.map { |a| a.name.to_s }
  if self._ransackable_associations.any?
    # Return intersection of all associations, and associations defined on the model
    all_associations & self._ransackable_associations
  else
    all_associations
  end
end
ransackable_attributes(auth_object = nil) click to toggle source

Return array of attributes with [name, type] (Default to :string type for ransackers)

# File lib/ransack_ui/adapters/active_record/base.rb, line 24
def ransackable_attributes(auth_object = nil)
  columns.map { |c| [c.name, c.type] } +
    _ransackers.keys.map { |k, v| [k, v.type || :string] }
end
ransortable_attributes(auth_object = nil) click to toggle source
# File lib/ransack_ui/adapters/active_record/base.rb, line 39
def ransortable_attributes(auth_object = nil)
  ransackable_attributes(auth_object).map(&:first)
end