Sha256: cb371348b516344370387c39d7dd91cd02c36c2b13b53ec7812ba48f6ad8f604
Contents?: true
Size: 1.09 KB
Versions: 4
Compression:
Stored size: 1.09 KB
Contents
class ActiveAdmin::Filters::FormBuilder def filter(method, options = {}) if method.present? && options[:as] ||= default_input_type(method) template.concat input(method, options) end end 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, :object; :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
4 entries across 4 versions & 1 rubygems