class ActiveAdmin::FilterFormBuilder

Public Instance Methods

column_for(method) click to toggle source
# File lib/active_admin/mongoid/filter_form_builder.rb, line 26
def column_for(method)
  @object.klass.fields[method.to_s] if @object.klass.respond_to?(:fields)
end
default_input_type(method, options = {}) click to toggle source
# File lib/active_admin/mongoid/filter_form_builder.rb, line 2
def default_input_type(method, options = {})
  if column = column_for(method)
    case column.type.name.downcase.to_sym
    when :date, :datetime, :time
      return :date_range
    when :string, :text, :object
      return :string
    when :integer
      return :select if reflection_for(method.to_s.gsub('_id','').to_sym)
      return :numeric
    when :float, :decimal
      return :numeric
    end
  elsif is_association?(method)
    return :select
  else # dirty but allows to create filters for hashes
    return :string
  end
end
is_association?(method) click to toggle source
# File lib/active_admin/mongoid/filter_form_builder.rb, line 22
def is_association?(method)
  @object.klass.associations.to_a.map(&:first).include?(method.to_s)
end
reflection_for(method) click to toggle source
# File lib/active_admin/mongoid/filter_form_builder.rb, line 30
def reflection_for(method)
  @object.klass.reflect_on_association(method) if @object.klass.respond_to?(:reflect_on_association)
end