[英]jruby rails undefined method `empty?' for nil:NilClass
我正在尝试在jruby rails环境中运行filterrific。 最初,没有错误,并且能够成功运行它。 在那之后的几天,我正在研究不同的控制器,并添加了一些其他与图表有关的宝石。 当我来到学生控制器时,现在它给了我这个错误,我已经对所有代码进行了三重验证,并且所做的一切都无法与您的演示应用程序和我的演示程序进行比较。 在视图,控制器,模型,js,数据库和配置文件中没有任何更改,但是突然我收到此错误“未定义的方法'空吗?' 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' }
进入以下几行,基本上我从选择选项中删除了filterrific,并使用ruby在表单中填充了选择选项。
= f.select :with_country_id, Country.all.collect {|u| [u.name, u.id]},
{ :include_blank => '- Any -' },
{ :class => 'form-control' }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.