Sha256: 3c75aa29d3ef56dc0ee4fab230f13e62bdde70239dc04570716c78c0d9d7b34c

Contents?: true

Size: 1.44 KB

Versions: 6

Compression:

Stored size: 1.44 KB

Contents

module ActiveAdmin
  module Inputs
    class FilterSelectInput < ::Formtastic::Inputs::SelectInput
      include FilterBase

      # If MetaSearch already responds to the given method, just use it.
      #
      # Otherwise:
      # When it's a HABTM or has_many association, Formtastic builds "object_ids".
      # That doesn't fit our scenario, so we override it here.
      def input_name
        return method if @object.respond_to? method

        name = method.to_s
        name.concat '_id' if reflection
        name.concat multiple? ? '_in' : '_eq'
      end

      # Provide the AA translation to the blank input field.
      def include_blank
        I18n.t 'active_admin.any' if super
      end

      # was "#{object_name}[#{association_primary_key}]"
      def input_html_options_name
        "#{object_name}[#{input_name}]"
      end

      # Would normally return true for has_many and HABTM, which would subsequently
      # cause the select field to be multi-select instead of a dropdown.
      def multiple_by_association?
        false
      end

      # Provides an efficient default lookup query if the attribute is a DB column.
      def collection
        unless Rails::VERSION::MAJOR == 3 && Rails::VERSION::MINOR < 2
          return pluck_column if !options[:collection] && column_for(method)
        end
        super
      end

      def pluck_column
        @object.base.reorder("#{method} asc").uniq.pluck method
      end

    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
activeadmin-0.6.6 lib/active_admin/inputs/filter_select_input.rb
activeadmin-0.6.5 lib/active_admin/inputs/filter_select_input.rb
activeadmin-0.6.4 lib/active_admin/inputs/filter_select_input.rb
activeadmin-0.6.3 lib/active_admin/inputs/filter_select_input.rb
activeadmin-0.6.2 lib/active_admin/inputs/filter_select_input.rb
activeadmin-0.6.1 lib/active_admin/inputs/filter_select_input.rb