activeadmin: undefined method `order_status_id_eq' for Ransack::Search>:Ransack::Search Extracted source (around line #2):

Same issue as #2565. but with a twist. Working with a Legacy database that doesn’t follow Rails convention.

On Rails 4.1.12 and master for activeadmin.

The Order model:

class Order < ActiveRecord::Base
  belongs_to  :order_status, foreign_key: :status
end

The AA DSL:

ActiveAdmin.register Order do
  index do
    selectable_column
    id_column
    column :order_status
    actions
  end

  filter :order_status
end

The Error:

ActionView::Template::Error (undefined method `order_status_id_eq' for Ransack::Search<class: Order, base: Grouping <combinator: and>>:Ransack::Search):
    1: insert_tag renderer_for(:index)
  ransack (1.6.6) lib/ransack/search.rb:113:in `method_missing'
  ransack (1.6.6) lib/ransack/helpers/form_builder.rb:10:in `value'
  actionview (4.1.12) lib/action_view/helpers/tags/select.rb:16:in `block in render'
  actionview (4.1.12) lib/action_view/helpers/tags/select.rb:16:in `fetch'
  actionview (4.1.12) lib/action_view/helpers/tags/select.rb:16:in `render'
  actionview (4.1.12) lib/action_view/helpers/form_options_helper.rb:163:in `select'
  actionview (4.1.12) lib/action_view/helpers/form_options_helper.rb:777:in `select'
  formtastic (3.1.3) lib/formtastic/inputs/select_input.rb:145:in `select_html'
  formtastic (3.1.3) lib/formtastic/inputs/select_input.rb:140:in `block in to_html'
  actionview (4.1.12) lib/action_view/helpers/capture_helper.rb:38:in `block in capture'
  actionview (4.1.12) lib/action_view/helpers/capture_helper.rb:202:in `with_output_buffer'
  actionview (4.1.12) lib/action_view/helpers/capture_helper.rb:38:in `capture'
  /Users/mwlang/.rvm/gems/ruby-2.1.5/bundler/gems/activeadmin-3254f53b4b35/lib/active_admin/inputs/filters/base.rb:12:in `input_wrapping'
  formtastic (3.1.3) lib/formtastic/inputs/select_input.rb:138:in `to_html'
  formtastic (3.1.3) lib/formtastic/helpers/input_helper.rb:240:in `input'
  /Users/mwlang/.rvm/gems/ruby-2.1.5/bundler/gems/activeadmin-3254f53b4b35/lib/active_admin/filters/forms.rb:14:in `filter'
  /Users/mwlang/.rvm/gems/ruby-2.1.5/bundler/gems/activeadmin-3254f53b4b35/lib/active_admin/filters/forms.rb:62:in `block (2 levels) in active_admin_filters_form_for'
  /Users/mwlang/.rvm/gems/ruby-2.1.5/bundler/gems/activeadmin-3254f53b4b35/lib/active_admin/filters/forms.rb:58:in `each'
  /Users/mwlang/.rvm/gems/ruby-2.1.5/bundler/gems/activeadmin-3254f53b4b35/lib/active_admin/filters/forms.rb:58:in `block in active_admin_filters_form_for'
  actionview (4.1.12) lib/action_view/helpers/capture_helper.rb:38:in `block in capture'
  actionview (4.1.12) lib/action_view/helpers/capture_helper.rb:202:in `with_output_buffer'
  actionview (4.1.12) lib/action_view/helpers/capture_helper.rb:38:in `capture'
  actionview (4.1.12) lib/action_view/helpers/form_helper.rb:434:in `form_for'
  /Users/mwlang/.rvm/gems/ruby-2.1.5/bundler/gems/activeadmin-3254f53b4b35/lib/active_admin/filters/forms.rb:57:in `active_admin_filters_form_for'
  arbre (1.0.3) lib/arbre/element.rb:180:in `method_missing'
  /Users/mwlang/.rvm/gems/ruby-2.1.5/bundler/gems/activeadmin-3254f53b4b35/lib/active_admin/filters/resource_extension.rb:151:in `block in filters_sidebar_section'
  /Users/mwlang/.rvm/gems/ruby-2.1.5/bundler/gems/activeadmin-3254f53b4b35/lib/active_admin/views/components/sidebar_section.rb:25:in `instance_exec'
  /Users/mwlang/.rvm/gems/ruby-2.1.5/bundler/gems/activeadmin-3254f53b4b35/lib/active_admin/views/components/sidebar_section.rb:25:in `build_sidebar_content'
  /Users/mwlang/.rvm/gems/ruby-2.1.5/bundler/gems/activeadmin-3254f53b4b35/lib/active_admin/views/components/sidebar_section.rb:13:in `build'
  arbre (1.0.3) lib/arbre/element/builder_methods.rb:30:in `block in build_tag'
  arbre (1.0.3) lib/arbre/context.rb:92:in `with_current_arbre_element'
  arbre (1.0.3) lib/arbre/element/builder_methods.rb:49:in `with_current_arbre_element'
  arbre (1.0.3) lib/arbre/element/builder_methods.rb:26:in `build_tag'
  arbre (1.0.3) lib/arbre/element/builder_methods.rb:39:in `insert_tag'
  arbre (1.0.3) lib/arbre/element/builder_methods.rb:14:in `sidebar_section'
  /Users/mwlang/.rvm/gems/ruby-2.1.5/bundler/gems/activeadmin-3254f53b4b35/lib/active_admin/views/pages/base.rb:130:in `block (2 levels) in build_sidebar'
  /Users/mwlang/.rvm/gems/ruby-2.1.5/bundler/gems/activeadmin-3254f53b4b35/lib/active_admin/views/pages/base.rb:129:in `collect'
  /Users/mwlang/.rvm/gems/ruby-2.1.5/bundler/gems/activeadmin-3254f53b4b35/lib/active_admin/views/pages/base.rb:129:in `block in build_sidebar'
  arbre (1.0.3) lib/arbre/element/builder_methods.rb:31:in `block in build_tag'
  arbre (1.0.3) lib/arbre/context.rb:92:in `with_current_arbre_element'
  arbre (1.0.3) lib/arbre/element/builder_methods.rb:49:in `with_current_arbre_element'
  arbre (1.0.3) lib/arbre/element/builder_methods.rb:26:in `build_tag'
  arbre (1.0.3) lib/arbre/element/builder_methods.rb:39:in `insert_tag'
  arbre (1.0.3) lib/arbre/element/builder_methods.rb:14:in `div'
  /Users/mwlang/.rvm/gems/ruby-2.1.5/bundler/gems/activeadmin-3254f53b4b35/lib/active_admin/views/pages/base.rb:128:in `build_sidebar'
  /Users/mwlang/.rvm/gems/ruby-2.1.5/bundler/gems/activeadmin-3254f53b4b35/lib/active_admin/views/pages/base.rb:76:in `block in build_page_content'
  arbre (1.0.3) lib/arbre/element/builder_methods.rb:31:in `block in build_tag'
  arbre (1.0.3) lib/arbre/context.rb:92:in `with_current_arbre_element'
  arbre (1.0.3) lib/arbre/element/builder_methods.rb:49:in `with_current_arbre_element'
  arbre (1.0.3) lib/arbre/element/builder_methods.rb:26:in `build_tag'
  arbre (1.0.3) lib/arbre/element/builder_methods.rb:39:in `insert_tag'
  arbre (1.0.3) lib/arbre/element/builder_methods.rb:14:in `div'
  /Users/mwlang/.rvm/gems/ruby-2.1.5/bundler/gems/activeadmin-3254f53b4b35/lib/active_admin/views/pages/base.rb:74:in `build_page_content'
  /Users/mwlang/.rvm/gems/ruby-2.1.5/bundler/gems/activeadmin-3254f53b4b35/lib/active_admin/views/pages/base.rb:52:in `block (2 levels) in build_page'
  arbre (1.0.3) lib/arbre/element/builder_methods.rb:31:in `block in build_tag'
  arbre (1.0.3) lib/arbre/context.rb:92:in `with_current_arbre_element'
  arbre (1.0.3) lib/arbre/element/builder_methods.rb:49:in `with_current_arbre_element'
  arbre (1.0.3) lib/arbre/element/builder_methods.rb:26:in `build_tag'
  arbre (1.0.3) lib/arbre/element/builder_methods.rb:39:in `insert_tag'
  arbre (1.0.3) lib/arbre/element/builder_methods.rb:14:in `div'
  /Users/mwlang/.rvm/gems/ruby-2.1.5/bundler/gems/activeadmin-3254f53b4b35/lib/active_admin/views/pages/base.rb:48:in `block in build_page'
  arbre (1.0.3) lib/arbre/context.rb:92:in `with_current_arbre_element'
  arbre (1.0.3) lib/arbre/element/builder_methods.rb:49:in `with_current_arbre_element'
  /Users/mwlang/.rvm/gems/ruby-2.1.5/bundler/gems/activeadmin-3254f53b4b35/lib/active_admin/views/pages/base.rb:47:in `build_page'
  /Users/mwlang/.rvm/gems/ruby-2.1.5/bundler/gems/activeadmin-3254f53b4b35/lib/active_admin/views/pages/base.rb:10:in `build'
  arbre (1.0.3) lib/arbre/element/builder_methods.rb:30:in `block in build_tag'
  arbre (1.0.3) lib/arbre/context.rb:92:in `with_current_arbre_element'
  arbre (1.0.3) lib/arbre/element/builder_methods.rb:26:in `build_tag'
  arbre (1.0.3) lib/arbre/element/builder_methods.rb:39:in `insert_tag'
  /Users/mwlang/.rvm/gems/ruby-2.1.5/bundler/gems/activeadmin-3254f53b4b35/app/views/active_admin/resource/index.html.arb:2:in `block in ___sers_mwlang__rvm_gems_ruby_______bundler_gems_activeadmin_____f__b_b___app_views_active_admin_resource_index_html_arb__2381377246843545787_70349303375080'
  arbre (1.0.3) lib/arbre/context.rb:45:in `instance_eval'
  arbre (1.0.3) lib/arbre/context.rb:45:in `initialize'
  /Users/mwlang/.rvm/gems/ruby-2.1.5/bundler/gems/activeadmin-3254f53b4b35/app/views/active_admin/resource/index.html.arb:1:in `new'
  /Users/mwlang/.rvm/gems/ruby-2.1.5/bundler/gems/activeadmin-3254f53b4b35/app/views/active_admin/resource/index.html.arb:1:in `___sers_mwlang__rvm_gems_ruby_______bundler_gems_activeadmin_____f__b_b___app_views_active_admin_resource_index_html_arb__2381377246843545787_70349303375080'
  actionview (4.1.12) lib/action_view/template.rb:145:in `block in render'
  activesupport (4.1.12) lib/active_support/notifications.rb:161:in `instrument'
  actionview (4.1.12) lib/action_view/template.rb:339:in `instrument'
  actionview (4.1.12) lib/action_view/template.rb:143:in `render'
  actionview (4.1.12) lib/action_view/renderer/template_renderer.rb:55:in `block (2 levels) in render_template'
  actionview (4.1.12) lib/action_view/renderer/abstract_renderer.rb:38:in `block in instrument'
  activesupport (4.1.12) lib/active_support/notifications.rb:159:in `block in instrument'
  activesupport (4.1.12) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
  activesupport (4.1.12) lib/active_support/notifications.rb:159:in `instrument'
  actionview (4.1.12) lib/action_view/renderer/abstract_renderer.rb:38:in `instrument'
  actionview (4.1.12) lib/action_view/renderer/template_renderer.rb:54:in `block in render_template'
  actionview (4.1.12) lib/action_view/renderer/template_renderer.rb:62:in `render_with_layout'
  actionview (4.1.12) lib/action_view/renderer/template_renderer.rb:53:in `render_template'
  actionview (4.1.12) lib/action_view/renderer/template_renderer.rb:17:in `render'
  actionview (4.1.12) lib/action_view/renderer/renderer.rb:42:in `render_template'
  actionview (4.1.12) lib/action_view/renderer/renderer.rb:23:in `render'
  actionview (4.1.12) lib/action_view/rendering.rb:99:in `_render_template'
  actionpack (4.1.12) lib/action_controller/metal/streaming.rb:217:in `_render_template'
  actionview (4.1.12) lib/action_view/rendering.rb:82:in `render_to_body'
  actionpack (4.1.12) lib/action_controller/metal/rendering.rb:32:in `render_to_body'
  actionpack (4.1.12) lib/action_controller/metal/renderers.rb:32:in `render_to_body'
  actionpack (4.1.12) lib/abstract_controller/rendering.rb:25:in `render'
  actionpack (4.1.12) lib/action_controller/metal/rendering.rb:16:in `render'
  actionpack (4.1.12) lib/action_controller/metal/instrumentation.rb:44:in `block (2 levels) in render'
  activesupport (4.1.12) lib/active_support/core_ext/benchmark.rb:12:in `block in ms'
  /Users/mwlang/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/benchmark.rb:294:in `realtime'
  activesupport (4.1.12) lib/active_support/core_ext/benchmark.rb:12:in `ms'
  actionpack (4.1.12) lib/action_controller/metal/instrumentation.rb:44:in `block in render'
  actionpack (4.1.12) lib/action_controller/metal/instrumentation.rb:87:in `cleanup_view_runtime'
  activerecord (4.1.12) lib/active_record/railties/controller_runtime.rb:25:in `cleanup_view_runtime'
  actionpack (4.1.12) lib/action_controller/metal/instrumentation.rb:43:in `render'
  actionpack (4.1.12) lib/action_controller/metal/implicit_render.rb:10:in `default_render'
  actionpack (4.1.12) lib/action_controller/metal/responder.rb:238:in `default_render'
  actionpack (4.1.12) lib/action_controller/metal/responder.rb:165:in `to_html'
  responders (1.1.2) lib/responders/flash_responder.rb:107:in `to_html'
  actionpack (4.1.12) lib/action_controller/metal/responder.rb:158:in `respond'
  actionpack (4.1.12) lib/action_controller/metal/responder.rb:151:in `call'
  actionpack (4.1.12) lib/action_controller/metal/mime_responds.rb:400:in `respond_with'
  inherited_resources (1.6.0) lib/inherited_resources/actions.rb:7:in `index'
  /Users/mwlang/.rvm/gems/ruby-2.1.5/bundler/gems/activeadmin-3254f53b4b35/lib/active_admin/resource_controller/streaming.rb:12:in `index'
  actionpack (4.1.12) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
  actionpack (4.1.12) lib/abstract_controller/base.rb:189:in `process_action'
  actionpack (4.1.12) lib/action_controller/metal/rendering.rb:10:in `process_action'
  actionpack (4.1.12) lib/abstract_controller/callbacks.rb:20:in `block in process_action'
  activesupport (4.1.12) lib/active_support/callbacks.rb:113:in `call'
  activesupport (4.1.12) lib/active_support/callbacks.rb:113:in `call'
  activesupport (4.1.12) lib/active_support/callbacks.rb:552:in `block (2 levels) in compile'
  activesupport (4.1.12) lib/active_support/callbacks.rb:502:in `call'
  activesupport (4.1.12) lib/active_support/callbacks.rb:502:in `call'
  activesupport (4.1.12) lib/active_support/callbacks.rb:86:in `run_callbacks'
  actionpack (4.1.12) lib/abstract_controller/callbacks.rb:19:in `process_action'
  actionpack (4.1.12) lib/action_controller/metal/rescue.rb:29:in `process_action'
  actionpack (4.1.12) lib/action_controller/metal/instrumentation.rb:32:in `block in process_action'
  activesupport (4.1.12) lib/active_support/notifications.rb:159:in `block in instrument'
  activesupport (4.1.12) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
  activesupport (4.1.12) lib/active_support/notifications.rb:159:in `instrument'
  actionpack (4.1.12) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
  actionpack (4.1.12) lib/action_controller/metal/params_wrapper.rb:250:in `process_action'
  activerecord (4.1.12) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
  actionpack (4.1.12) lib/abstract_controller/base.rb:136:in `process'
  actionview (4.1.12) lib/action_view/rendering.rb:30:in `process'
  actionpack (4.1.12) lib/action_controller/metal.rb:196:in `dispatch'
  actionpack (4.1.12) lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'
  actionpack (4.1.12) lib/action_controller/metal.rb:232:in `block in action'
  actionpack (4.1.12) lib/action_dispatch/routing/route_set.rb:82:in `call'
  actionpack (4.1.12) lib/action_dispatch/routing/route_set.rb:82:in `dispatch'
  actionpack (4.1.12) lib/action_dispatch/routing/route_set.rb:50:in `call'
  actionpack (4.1.12) lib/action_dispatch/journey/router.rb:73:in `block in call'
  actionpack (4.1.12) lib/action_dispatch/journey/router.rb:59:in `each'
  actionpack (4.1.12) lib/action_dispatch/journey/router.rb:59:in `call'
  actionpack (4.1.12) lib/action_dispatch/routing/route_set.rb:692:in `call'
  warden (1.2.3) lib/warden/manager.rb:35:in `block in call'
  warden (1.2.3) lib/warden/manager.rb:34:in `catch'
  warden (1.2.3) lib/warden/manager.rb:34:in `call'
  rack (1.5.5) lib/rack/etag.rb:23:in `call'
  rack (1.5.5) lib/rack/conditionalget.rb:25:in `call'
  rack (1.5.5) lib/rack/head.rb:11:in `call'
  actionpack (4.1.12) lib/action_dispatch/middleware/params_parser.rb:27:in `call'
  actionpack (4.1.12) lib/action_dispatch/middleware/flash.rb:254:in `call'
  rack (1.5.5) lib/rack/session/abstract/id.rb:225:in `context'
  rack (1.5.5) lib/rack/session/abstract/id.rb:220:in `call'
  actionpack (4.1.12) lib/action_dispatch/middleware/cookies.rb:562:in `call'
  activerecord (4.1.12) lib/active_record/query_cache.rb:36:in `call'
  activerecord (4.1.12) lib/active_record/connection_adapters/abstract/connection_pool.rb:621:in `call'
  activerecord (4.1.12) lib/active_record/migration.rb:380:in `call'
  actionpack (4.1.12) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
  activesupport (4.1.12) lib/active_support/callbacks.rb:82:in `run_callbacks'
  actionpack (4.1.12) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
  actionpack (4.1.12) lib/action_dispatch/middleware/reloader.rb:73:in `call'
  actionpack (4.1.12) lib/action_dispatch/middleware/remote_ip.rb:76:in `call'
  actionpack (4.1.12) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
  actionpack (4.1.12) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
  railties (4.1.12) lib/rails/rack/logger.rb:38:in `call_app'
  railties (4.1.12) lib/rails/rack/logger.rb:20:in `block in call'
  activesupport (4.1.12) lib/active_support/tagged_logging.rb:68:in `block in tagged'
  activesupport (4.1.12) lib/active_support/tagged_logging.rb:26:in `tagged'
  activesupport (4.1.12) lib/active_support/tagged_logging.rb:68:in `tagged'
  railties (4.1.12) lib/rails/rack/logger.rb:20:in `call'
  actionpack (4.1.12) lib/action_dispatch/middleware/request_id.rb:21:in `call'
  rack (1.5.5) lib/rack/methodoverride.rb:21:in `call'
  rack (1.5.5) lib/rack/runtime.rb:17:in `call'
  activesupport (4.1.12) lib/active_support/cache/strategy/local_cache_middleware.rb:26:in `call'
  rack (1.5.5) lib/rack/lock.rb:17:in `call'
  actionpack (4.1.12) lib/action_dispatch/middleware/static.rb:84:in `call'
  rack (1.5.5) lib/rack/sendfile.rb:112:in `call'
  railties (4.1.12) lib/rails/engine.rb:514:in `call'
  railties (4.1.12) lib/rails/application.rb:144:in `call'
  rack (1.5.5) lib/rack/content_length.rb:14:in `call'
  thin (1.6.3) lib/thin/connection.rb:86:in `block in pre_process'
  thin (1.6.3) lib/thin/connection.rb:84:in `catch'
  thin (1.6.3) lib/thin/connection.rb:84:in `pre_process'
  thin (1.6.3) lib/thin/connection.rb:53:in `process'
  thin (1.6.3) lib/thin/connection.rb:39:in `receive_data'
  eventmachine (1.0.8) lib/eventmachine.rb:193:in `run_machine'
  eventmachine (1.0.8) lib/eventmachine.rb:193:in `run'
  thin (1.6.3) lib/thin/backends/base.rb:73:in `start'
  thin (1.6.3) lib/thin/server.rb:162:in `start'
  rack (1.5.5) lib/rack/handler/thin.rb:16:in `run'
  rack (1.5.5) lib/rack/server.rb:264:in `start'
  railties (4.1.12) lib/rails/commands/server.rb:69:in `start'
  railties (4.1.12) lib/rails/commands/commands_tasks.rb:81:in `block in server'
  railties (4.1.12) lib/rails/commands/commands_tasks.rb:76:in `tap'
  railties (4.1.12) lib/rails/commands/commands_tasks.rb:76:in `server'
  railties (4.1.12) lib/rails/commands/commands_tasks.rb:40:in `run_command!'
  railties (4.1.12) lib/rails/commands.rb:17:in `<top (required)>'
  bin/rails:8:in `require'
  bin/rails:8:in `<top (required)>'
  spring (1.3.6) lib/spring/client/rails.rb:28:in `load'
  spring (1.3.6) lib/spring/client/rails.rb:28:in `call'
  spring (1.3.6) lib/spring/client/command.rb:7:in `call'
  spring (1.3.6) lib/spring/client.rb:26:in `run'
  spring (1.3.6) bin/spring:48:in `<top (required)>'
  spring (1.3.6) lib/spring/binstub.rb:11:in `load'
  spring (1.3.6) lib/spring/binstub.rb:11:in `<top (required)>'
  bin/spring:13:in `require'
  bin/spring:13:in `<top (required)>'
  bin/rails:3:in `load'
  bin/rails:3:in `<main>'


  Rendered /Users/mwlang/.rvm/gems/ruby-2.1.5/gems/actionpack-4.1.12/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (1.0ms)
  Rendered /Users/mwlang/.rvm/gems/ruby-2.1.5/gems/actionpack-4.1.12/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb (1.2ms)
  Rendered /Users/mwlang/.rvm/gems/ruby-2.1.5/gems/actionpack-4.1.12/lib/action_dispatch/middleware/templates/rescues/template_error.html.erb within rescues/layout (11.4ms)

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Comments: 22 (9 by maintainers)

Most upvoted comments

@deivid-rodriguez I would, but my schedule’s overflowing for a while and frankly, I’ve forgotten much of what I learned about the internals of Active Admin.

However, what I can do is share all the monkey patches I applied to the project back when I was encountering these issues and these follow below. If I recall correctly, it’s the second one below that solves this specific issue.

module ActiveAdmin
  ###################################################################################
  # Allows scope names to be translated before displaying
  #
  class Scope
    def name
      display_text = case @name
        when Proc   then @name.call.to_s
        when String then @name
        when Symbol then @name.to_s.titleize
        else             @name.to_s
      end
      I18n.translate(display_text, scope: [:active_admin, :scope], default: display_text)
    end
  end

  ###################################################################################
  # Solves issues with filters being rendered on non-railsy associations
  #
  module Inputs
    module Filters
      class SelectInput < ::Formtastic::Inputs::SelectInput

        def input_name
          return method if seems_searchable?
          searchable_method_name.dup.concat multiple? ? '_in' : '_eq'
        end

        def searchable_method_name
          if searchable_has_many_through?
            "#{reflection.through_reflection.name}_#{reflection.foreign_key}"
          elsif (name = reflection.try(:foreign_key).to_s).present? && klass.ransackable_attributes.include?(name)
            name
          else
            name = method.to_s
            name.concat '_id' if reflection
            if name == "payment_types_id"
              raise [name, reflection.name, reflection.foreign_key.to_s, klass.ransackable_attributes].inspect
            end
            name
          end
        end
      end
    end
  end
end

###################################################################################
# Translates the filter predicate names
#
module ActiveAdmin
  module Filters
    class Humanized

      private

      def parse_parameter_body
        return if current_predicate.nil?

        # Accounting for strings that might contain other predicates. Example:
        # 'requires_approval' contains the substring 'eq'
        split_string = "_#{current_predicate}"

        value = @body.split(split_string)
          .first
          .gsub('_', ' ')
          .strip
          .titleize
          .gsub('Id', 'ID')
        I18n.translate(value, scope: [:active_admin, :predicates, :attributes], default: value)
      end
    end
  end
end

###################################################################################
# Translates the scope names
#
module ActiveAdmin
  module Filters
    module ResourceExtension
    private

      def search_status_section
        ActiveAdmin::SidebarSection.new :search_status, only: :index, if: -> { params[:q] || params[:scope] } do
          active = ActiveAdmin::Filters::Active.new(resource_class, params)

          span do
            h4 I18n.t("active_admin.search_status.headline"), style: 'display: inline'
            b I18n.t(active.scope, scope: [:active_admin, :scope], default: active.scope), style: "display: inline"

            div style: "margin-top: 10px" do
              h4 I18n.t("active_admin.search_status.current_filters"), style: 'margin-bottom: 10px'
              ul do
                if active.filters.blank?
                  li I18n.t("active_admin.search_status.no_current_filters")
                else
                  active.filters.each do |filter|
                    li do
                      span I18n.t(filter.body, scope: [:active_admin, :scope], default: filter.body)
                      b filter.value
                    end
                  end
                end
              end
            end
          end
        end
      end
    end

  end
end