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
6 7 8 9 10 11 12 13 |
# File 'lib/ransack_ui/adapters/active_record/base.rb', line 6 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
15 16 17 |
# File 'lib/ransack_ui/adapters/active_record/base.rb', line 15 def has_ransackable_associations(associations) self._ransackable_associations = associations end |
#ransack_can_autocomplete ⇒ Object
19 20 21 |
# File 'lib/ransack_ui/adapters/active_record/base.rb', line 19 def ransack_can_autocomplete self._ransack_can_autocomplete = true end |
#ransackable_associations(auth_object = nil) ⇒ Object
30 31 32 33 34 35 36 37 38 |
# File 'lib/ransack_ui/adapters/active_record/base.rb', line 30 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)
25 26 27 28 |
# File 'lib/ransack_ui/adapters/active_record/base.rb', line 25 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
40 41 42 |
# File 'lib/ransack_ui/adapters/active_record/base.rb', line 40 def ransortable_attributes(auth_object = nil) ransackable_attributes(auth_object).map(&:first) end |