Sha256: 854b11d87041de2feab79f70dd8153163598126e4341e90262bb27f91c8c62ab

Contents?: true

Size: 948 Bytes

Versions: 2

Compression:

Stored size: 948 Bytes

Contents

class ActiveAdmin::FilterFormBuilder
  def default_input_type(method, options = {})
    if column = column_for(method)
      case column.type.name.downcase.to_sym
      when :date, :datetime, :time;   :date_range
      when :string, :text, :objectl;  :string
      when :float, :decimal;          :numeric
      when :integer
        return :select if reflection_for(method.to_s.gsub('_id','').to_sym)
        return :numeric
      end
    elsif is_association?(method)
      return :select
    else
      # dirty but allows to create filters for hashes
      return :string
    end
  end

  def is_association?(method)
    @object.klass.associations.to_a.map(&:first).include?(method.to_s)
  end

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

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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
activeadmin-mongoid-0.3.0 lib/active_admin/mongoid/filter_form_builder.rb
activeadmin-mongoid-0.2.0 lib/active_admin/mongoid/filter_form_builder.rb