jruby rails 未定义方法“空?” nil:NilClass
jruby rails undefined method `empty?' for nil:NilClass
我正尝试在 jruby rails 环境中 运行 filterrific。最初,没有任何错误,并且能够 运行 成功。几天后,我在不同的控制器上工作,添加了一些与图表相关的其他宝石。当我来到学生控制器时,现在它给了我这个错误,我已经三次验证了所有代码,并且与你的演示应用程序和我的相比也做得更好。视图、控制器、模型、js、数据库和配置文件没有变化,但突然我在下面的行 "undefined method `empty?' for nil:NilClass" 中收到此错误
.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' }
应用程序跟踪:
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'
完整跟踪:
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'
有人可以帮忙吗?
经过一天的努力不知何故找到了解决方法,如果有人能更好地解释问题所在,那就太好了。想要答案的小伙伴请看下面。
我更改了以下行
= f.select :with_country_id,
@filterrific.select_options[:with_country_id],
{ :include_blank => '- Any -' },
{ :class => 'form-control' }
到下面几行,基本上我从 select 选项中删除了 filterrific 并使用 ruby.
填充了表单中的 select 选项
= f.select :with_country_id, Country.all.collect {|u| [u.name, u.id]},
{ :include_blank => '- Any -' },
{ :class => 'form-control' }
我正尝试在 jruby rails 环境中 运行 filterrific。最初,没有任何错误,并且能够 运行 成功。几天后,我在不同的控制器上工作,添加了一些与图表相关的其他宝石。当我来到学生控制器时,现在它给了我这个错误,我已经三次验证了所有代码,并且与你的演示应用程序和我的相比也做得更好。视图、控制器、模型、js、数据库和配置文件没有变化,但突然我在下面的行 "undefined method `empty?' for nil:NilClass" 中收到此错误
.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' }
应用程序跟踪:
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'
完整跟踪:
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'
有人可以帮忙吗?
经过一天的努力不知何故找到了解决方法,如果有人能更好地解释问题所在,那就太好了。想要答案的小伙伴请看下面。
我更改了以下行
= f.select :with_country_id,
@filterrific.select_options[:with_country_id],
{ :include_blank => '- Any -' },
{ :class => 'form-control' }
到下面几行,基本上我从 select 选项中删除了 filterrific 并使用 ruby.
填充了表单中的 select 选项= f.select :with_country_id, Country.all.collect {|u| [u.name, u.id]},
{ :include_blank => '- Any -' },
{ :class => 'form-control' }