Class: ActiveAdmin::Filters::FormBuilder
- Inherits:
-
Object
- Object
- ActiveAdmin::Filters::FormBuilder
- Defined in:
- lib/active_admin/mongoid/filter_form_builder.rb
Instance Method Summary collapse
- #column_for(method) ⇒ Object
- #default_input_type(method, options = {}) ⇒ Object
- #filter(method, options = {}) ⇒ Object
- #is_association?(method) ⇒ Boolean
- #reflection_for(method) ⇒ Object
Instance Method Details
#column_for(method) ⇒ Object
31 32 33 |
# File 'lib/active_admin/mongoid/filter_form_builder.rb', line 31 def column_for(method) @object.klass.fields[method.to_s] if @object.klass.respond_to?(:fields) end |
#default_input_type(method, options = {}) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/active_admin/mongoid/filter_form_builder.rb', line 9 def default_input_type(method, = {}) 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 |
#filter(method, options = {}) ⇒ Object
3 4 5 6 7 |
# File 'lib/active_admin/mongoid/filter_form_builder.rb', line 3 def filter(method, = {}) if method.present? && [:as] ||= default_input_type(method) template.concat input(method, ) end end |
#is_association?(method) ⇒ Boolean
27 28 29 |
# File 'lib/active_admin/mongoid/filter_form_builder.rb', line 27 def is_association?(method) @object.klass.associations.to_a.map!(&:first).include?(method.to_s) end |
#reflection_for(method) ⇒ Object
35 36 37 |
# File 'lib/active_admin/mongoid/filter_form_builder.rb', line 35 def reflection_for(method) @object.klass.reflect_on_association(method) if @object.klass.respond_to?(:reflect_on_association) end |