jhund / filterrific

Filterrific is a Rails Engine plugin that makes it easy to filter, search, and sort your ActiveRecord lists.
http://filterrific.clearcove.ca
MIT License
910 stars 124 forks source link

undefined method `empty?' for nil:NilClass #133

Closed balajibalasubramaniam closed 6 years ago

balajibalasubramaniam commented 7 years ago

Hi, I am trying to run filterrific in jruby rails environment. Initially, there was no errors and was able to run it succesffully. Few days after that I was working on different controller adding some other gems related with charts. When I came to student controller, now it is giving me this error, I have triple verified all the code and also did beyond compare with your demo app and mine. There was no changes in views, controller, model, js, db and config files, but suddenly I am getting this error "undefined method `empty?' for nil:NilClass" in the following line

    .form-group.chardin_box{ :'data-position' => 'top', :'data-intro' => 'Filter by country.' }
      %label Category
      = f.select :with_country_id,
                 @filterrific.select_options[:with_country_id],
                 { :include_blank => '- Any -' },
                 { :class => 'form-control' }

Can you please help?

Application Trace

app/views/students/index.html.haml:22:in block in _app_views_students_index_html_haml___1163931893_2080' app/views/students/index.html.haml:12:in_app_views_students_index_html_haml___1163931893_2080'

Full Trace

actionview (5.1.1) lib/action_view/helpers/tags/select.rb:36:in grouped_choices?' actionview (5.1.1) lib/action_view/helpers/tags/select.rb:20:inrender' actionview (5.1.1) lib/action_view/helpers/form_options_helper.rb:163:in select' actionview (5.1.1) lib/action_view/helpers/form_options_helper.rb:817:inselect' app/views/students/index.html.haml:22:in block in _app_views_students_index_html_haml___1163931893_2080' haml (5.0.1) lib/haml/helpers.rb:382:inblock in capture_haml' haml (5.0.1) lib/haml/helpers.rb:667:in with_haml_buffer' haml (5.0.1) lib/haml/helpers.rb:378:incapture_haml' haml (5.0.1) lib/haml/helpers/xss_mods.rb:62:in capture_haml_with_haml_xss' haml (5.0.1) lib/haml/helpers/action_view_mods.rb:45:incapture_with_haml' actionview (5.1.1) lib/action_view/helpers/form_helper.rb:450:in form_for' haml (5.0.1) lib/haml/helpers/action_view_xss_mods.rb:29:inform_for_with_haml_xss' filterrific (2.1.2) lib/filterrific/action_view_extension.rb:23:in form_for_filterrific' app/views/students/index.html.haml:12:in_app_views_students_index_html_haml___1163931893_2080' actionview (5.1.1) lib/action_view/template.rb:157:in block in render' activesupport (5.1.1) lib/active_support/notifications.rb:168:ininstrument' actionview (5.1.1) lib/action_view/template.rb:352:in instrument_render_template' actionview (5.1.1) lib/action_view/template.rb:155:inrender' actionview (5.1.1) lib/action_view/renderer/template_renderer.rb:52:in block in render_template' actionview (5.1.1) lib/action_view/renderer/abstract_renderer.rb:42:inblock in instrument' activesupport (5.1.1) lib/active_support/notifications.rb:166:in block in instrument' activesupport (5.1.1) lib/active_support/notifications/instrumenter.rb:21:ininstrument' activesupport (5.1.1) lib/active_support/notifications.rb:166:in instrument' actionview (5.1.1) lib/action_view/renderer/abstract_renderer.rb:41:ininstrument' actionview (5.1.1) lib/action_view/renderer/template_renderer.rb:51:in block in render_template' actionview (5.1.1) lib/action_view/renderer/template_renderer.rb:59:inrender_with_layout' actionview (5.1.1) lib/action_view/renderer/template_renderer.rb:50:in render_template' actionview (5.1.1) lib/action_view/renderer/template_renderer.rb:14:inrender' actionview (5.1.1) lib/action_view/renderer/renderer.rb:42:in render_template' actionview (5.1.1) lib/action_view/renderer/renderer.rb:23:inrender' actionview (5.1.1) lib/action_view/rendering.rb:103:in _render_template' actionpack (5.1.1) lib/action_controller/metal/streaming.rb:217:in_render_template' actionview (5.1.1) lib/action_view/rendering.rb:83:in render_to_body' actionpack (5.1.1) lib/action_controller/metal/rendering.rb:52:inrender_to_body' actionpack (5.1.1) lib/action_controller/metal/renderers.rb:141:in render_to_body' actionpack (5.1.1) lib/abstract_controller/rendering.rb:24:inrender' actionpack (5.1.1) lib/action_controller/metal/rendering.rb:36:in render' actionpack (5.1.1) lib/action_controller/metal/instrumentation.rb:44:inblock in render' activesupport (5.1.1) lib/active_support/core_ext/benchmark.rb:12:in block in ms' /home/balaji/Documents/balaji/unl/PhD/railswebapp/jruby-9.1.10.0/lib/ruby/stdlib/benchmark.rb:308:inrealtime' activesupport (5.1.1) lib/active_support/core_ext/benchmark.rb:12:in ms' actionpack (5.1.1) lib/action_controller/metal/instrumentation.rb:44:inblock in render' actionpack (5.1.1) lib/action_controller/metal/instrumentation.rb:87:in cleanup_view_runtime' activerecord (5.1.1) lib/active_record/railties/controller_runtime.rb:29:incleanup_view_runtime' actionpack (5.1.1) lib/action_controller/metal/instrumentation.rb:43:in render' actionpack (5.1.1) lib/action_controller/metal/implicit_render.rb:33:indefault_render' actionpack (5.1.1) lib/action_controller/metal/basic_implicit_render.rb:4:in block in send_action' org/jruby/RubyKernel.java:1747:intap' actionpack (5.1.1) lib/action_controller/metal/basic_implicit_render.rb:4:in send_action' actionpack (5.1.1) lib/abstract_controller/base.rb:186:inprocess_action' actionpack (5.1.1) lib/action_controller/metal/rendering.rb:30:in process_action' actionpack (5.1.1) lib/abstract_controller/callbacks.rb:20:inblock in process_action' activesupport (5.1.1) lib/active_support/callbacks.rb:131:in run_callbacks' actionpack (5.1.1) lib/abstract_controller/callbacks.rb:19:inprocess_action' actionpack (5.1.1) lib/action_controller/metal/rescue.rb:20:in process_action' actionpack (5.1.1) lib/action_controller/metal/instrumentation.rb:32:inblock in process_action' activesupport (5.1.1) lib/active_support/notifications.rb:166:in block in instrument' activesupport (5.1.1) lib/active_support/notifications/instrumenter.rb:21:ininstrument' activesupport (5.1.1) lib/active_support/notifications.rb:166:in instrument' actionpack (5.1.1) lib/action_controller/metal/instrumentation.rb:30:inprocess_action' actionpack (5.1.1) lib/action_controller/metal/params_wrapper.rb:252:in process_action' activerecord (5.1.1) lib/active_record/railties/controller_runtime.rb:22:inprocess_action' actionpack (5.1.1) lib/abstract_controller/base.rb:124:in process' actionview (5.1.1) lib/action_view/rendering.rb:30:inprocess' actionpack (5.1.1) lib/action_controller/metal.rb:189:in dispatch' actionpack (5.1.1) lib/action_controller/metal.rb:253:indispatch' actionpack (5.1.1) lib/action_dispatch/routing/route_set.rb:49:in dispatch' actionpack (5.1.1) lib/action_dispatch/routing/route_set.rb:31:inserve' actionpack (5.1.1) lib/action_dispatch/journey/router.rb:46:in block in serve' org/jruby/RubyArray.java:1734:ineach' actionpack (5.1.1) lib/action_dispatch/journey/router.rb:33:in serve' actionpack (5.1.1) lib/action_dispatch/routing/route_set.rb:832:incall' rack (2.0.3) lib/rack/etag.rb:25:in call' rack (2.0.3) lib/rack/conditional_get.rb:25:incall' rack (2.0.3) lib/rack/head.rb:12:in call' torquebox-web-3.2.0 (java) lib/torquebox/session/servlet_store.rb:47:incall' actionpack (5.1.1) lib/action_dispatch/middleware/cookies.rb:613:in call' activerecord (5.1.1) lib/active_record/migration.rb:556:incall' actionpack (5.1.1) lib/action_dispatch/middleware/callbacks.rb:26:in block in call' activesupport (5.1.1) lib/active_support/callbacks.rb:97:inrun_callbacks' actionpack (5.1.1) lib/action_dispatch/middleware/callbacks.rb:24:in call' actionpack (5.1.1) lib/action_dispatch/middleware/executor.rb:12:incall' actionpack (5.1.1) lib/action_dispatch/middleware/debug_exceptions.rb:59:in call' actionpack (5.1.1) lib/action_dispatch/middleware/show_exceptions.rb:31:incall' railties (5.1.1) lib/rails/rack/logger.rb:36:in call_app' railties (5.1.1) lib/rails/rack/logger.rb:24:inblock in call' activesupport (5.1.1) lib/active_support/tagged_logging.rb:69:in block in tagged' activesupport (5.1.1) lib/active_support/tagged_logging.rb:26:intagged' activesupport (5.1.1) lib/active_support/tagged_logging.rb:69:in tagged' railties (5.1.1) lib/rails/rack/logger.rb:24:incall' sprockets-rails (3.2.0) lib/sprockets/rails/quiet_assets.rb:13:in call' actionpack (5.1.1) lib/action_dispatch/middleware/remote_ip.rb:79:incall' actionpack (5.1.1) lib/action_dispatch/middleware/request_id.rb:25:in call' rack (2.0.3) lib/rack/method_override.rb:22:incall' rack (2.0.3) lib/rack/runtime.rb:22:in call' activesupport (5.1.1) lib/active_support/cache/strategy/local_cache_middleware.rb:27:incall' actionpack (5.1.1) lib/action_dispatch/middleware/executor.rb:12:in call' actionpack (5.1.1) lib/action_dispatch/middleware/static.rb:125:incall' rack (2.0.3) lib/rack/sendfile.rb:111:in call' railties (5.1.1) lib/rails/engine.rb:522:incall'

balajibalasubramaniam commented 7 years ago

when I print @filterrific.select_options, then in the console I get the following: {\"sorted_by\"=>[[\"Name (a-z)\", \"name_asc\"], [\"Commited date (newest first)\", \"created_at_desc\"], [\"Commited date (oldest first)\", \"created_at_asc\"], [\"Category (a-z)\", \"country_name_asc\"]], \"with_country_id\"=>[[\"Australia\", 3], [\"Canada\", 2], [\"Ireland\", 7], [\"New Zealand\", 5], [\"Puerto Rico\", 6], [\"South Africa\", 4], [\"United Kingdom\", 8], [\"United States\", 1]]}

jhund commented 6 years ago

@balajibalasubramaniam in the printout of .select_options, you can see that the Hash uses string keys. So in order to make this work, you need to change @filterrific.select_options[:with_country_id] to @filterrific.select_options["with_country_id"]. Notice the String hash key for "with_country_id".