Class: ActiveAdmin::Filters::FormBuilder
- Inherits:
-
ActiveAdmin::FormBuilder
- Object
- Formtastic::FormBuilder
- ActiveAdmin::FormBuilder
- ActiveAdmin::Filters::FormBuilder
- Defined in:
- lib/active_admin/filters/forms.rb
Overview
This form builder defines methods to build filter forms such as the one found in the sidebar of the index page of a standard resource.
Instance Attribute Summary
Attributes inherited from ActiveAdmin::FormBuilder
Instance Method Summary collapse
- #active_admin_input_class_name(as) ⇒ Object protected
-
#column_for(method) ⇒ Object
protected
Returns the column for an attribute on the object being searched if it exists.
- #custom_input_class_name(as) ⇒ Object protected
-
#default_input_type(method, options = {}) ⇒ Object
protected
Returns the default filter type for a given attribute.
- #filter(method, options = {}) ⇒ Object
-
#reflection_for(method) ⇒ Object
protected
Returns the association reflection for the method if it exists.
Methods inherited from ActiveAdmin::FormBuilder
#action, #actions, #cancel_link, #commit_action_with_cancel_link, #field_set_and_list_wrapping, #has_many, #initialize, #input, #input_class_by_trying, #input_class_with_const_defined, #inputs, #semantic_errors
Methods included from ActiveAdmin::FormBuilder::DeprecatedMethods
#buttons, #commit_button, #commit_button_with_cancel_link
Constructor Details
This class inherits a constructor from ActiveAdmin::FormBuilder
Instance Method Details
#active_admin_input_class_name(as) ⇒ Object (protected)
44 45 46 |
# File 'lib/active_admin/filters/forms.rb', line 44 def active_admin_input_class_name(as) "ActiveAdmin::Inputs::Filter#{as.to_s.camelize}Input" end |
#column_for(method) ⇒ Object (protected)
Returns the column for an attribute on the object being searched if it exists. Otherwise returns nil
50 51 52 |
# File 'lib/active_admin/filters/forms.rb', line 50 def column_for(method) @object.base.columns_hash[method.to_s] if @object.base.respond_to?(:columns_hash) end |
#custom_input_class_name(as) ⇒ Object (protected)
40 41 42 |
# File 'lib/active_admin/filters/forms.rb', line 40 def custom_input_class_name(as) "Filter#{as.to_s.camelize}Input" end |
#default_input_type(method, options = {}) ⇒ Object (protected)
Returns the default filter type for a given attribute
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/active_admin/filters/forms.rb', line 18 def default_input_type(method, = {}) if (column = column_for(method)) case column.type when :date, :datetime return :date_range when :string, :text return :string when :integer return :select if reflection_for(method.to_s.gsub('_id','').to_sym) return :numeric when :float, :decimal return :numeric when :boolean return :boolean end end if (reflection = reflection_for(method)) return :select if reflection.macro == :belongs_to && !reflection.[:polymorphic] end end |
#filter(method, options = {}) ⇒ Object
8 9 10 11 12 13 |
# File 'lib/active_admin/filters/forms.rb', line 8 def filter(method, = {}) return "" if method.blank? || ([:as] ||= default_input_type(method)).nil? content = input(method, ) form_buffers.last << content.html_safe if content end |
#reflection_for(method) ⇒ Object (protected)
Returns the association reflection for the method if it exists
55 56 57 |
# File 'lib/active_admin/filters/forms.rb', line 55 def reflection_for(method) @object.base.reflect_on_association(method) if @object.base.respond_to?(:reflect_on_association) end |