Module: RansackUI::Adapters::ActiveRecord::Base
- Defined in:
- lib/ransack_ui/adapters/active_record/base.rb
Class Method Summary collapse
Instance Method Summary collapse
- #has_ransackable_associations(associations) ⇒ Object
- #ransack_can_autocomplete ⇒ Object
- #ransackable_associations(auth_object = nil) ⇒ Object
-
#ransackable_attributes(auth_object = nil) ⇒ Object
Return array of attributes with [name, type] (Default to :string type for ransackers).
- #ransortable_attributes(auth_object = nil) ⇒ Object
Class Method Details
.extended(base) ⇒ Object
5 6 7 8 9 10 11 12 |
# 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 |
Instance Method Details
#has_ransackable_associations(associations) ⇒ Object
14 15 16 |
# File 'lib/ransack_ui/adapters/active_record/base.rb', line 14 def has_ransackable_associations(associations) self._ransackable_associations = associations end |
#ransack_can_autocomplete ⇒ Object
18 19 20 |
# 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) ⇒ Object
29 30 31 32 33 34 35 36 37 |
# 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) ⇒ Object
Return array of attributes with [name, type] (Default to :string type for ransackers)
24 25 26 27 |
# 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) ⇒ Object
39 40 41 |
# File 'lib/ransack_ui/adapters/active_record/base.rb', line 39 def ransortable_attributes(auth_object = nil) ransackable_attributes(auth_object).map(&:first) end |