Module: ActiveAdmin::Filters::FormtasticAddons

Included in:
FormBuilder, Inputs::FilterBase
Defined in:
lib/active_admin/filters/formtastic_addons.rb

Instance Method Summary collapse

Instance Method Details

#column_for(method) ⇒ Object

Returns the column for an attribute on the object being searched if it exists.



24
25
26
# File 'lib/active_admin/filters/formtastic_addons.rb', line 24

def column_for(method)
  @object.base.columns_hash[method.to_s] if @object.base.respond_to?(:columns_hash)
end

#foreign_key?(method) ⇒ Boolean

The below are custom methods that Formtastic does not provide.

Returns:

  • (Boolean)


32
33
34
35
# File 'lib/active_admin/filters/formtastic_addons.rb', line 32

def foreign_key?(method)
  @object.base.reflections.select{ |_,r| r.macro == :belongs_to }.values
    .map(&:foreign_key).include? method.to_s
end

#humanized_method_nameObject

Returns the default label for a given attribute. Uses ActiveModel I18n if available.



10
11
12
13
14
15
16
# File 'lib/active_admin/filters/formtastic_addons.rb', line 10

def humanized_method_name
  if object.base.respond_to?(:human_attribute_name)
    object.base.human_attribute_name(method)
  else
    method.to_s.send(builder.label_str_method)
  end
end

#polymorphic_foreign_type?(method) ⇒ Boolean

Returns:

  • (Boolean)


37
38
39
40
41
# File 'lib/active_admin/filters/formtastic_addons.rb', line 37

def polymorphic_foreign_type?(method)
  type = Rails::VERSION::MAJOR == 3 && Rails::VERSION::MINOR == 0 ? proc{ |r| r.options[:foreign_type] } : :foreign_type
  @object.base.reflections.values.select{ |r| r.macro == :belongs_to && r.options[:polymorphic] }
    .map(&type).include? method.to_s
end

#reflection_for(method) ⇒ Object

Returns the association reflection for the method if it exists



19
20
21
# File 'lib/active_admin/filters/formtastic_addons.rb', line 19

def reflection_for(method)
  @object.base.reflect_on_association(method) if @object.base.respond_to?(:reflect_on_association)
end