升级到 rails 4.2.5.1 后 nil:NilClass 的未定义方法“缓存”
undefined method `cache' for nil:NilClass after upgrading to rails 4.2.5.1
从rails4.2.5
升级到最近发布的4.2.5.1
时,我遇到了这个错误。此错误仅存在于具有呈现无效状态的 before_filter
的规格,例如 render file: "public/422", status: :unauthorized
。 ruby-2.2.2 和 ruby-2.3.0
都出现了这个错误
错误存在于 action_view 解析器方法中,暗示 @cache
值为 nil。但是,在 initialize
方法中它应该被实例化: @cache = Cache.new
我仍在研究可重现的样本,但到目前为止我不知道 @cache
怎么可能是零。
这些是在我的 test.rb
环境中设置的配置变量
config.cache_classes = true
config.eager_load = false
config.serve_static_files = true
config.static_cache_control = 'public, max-age=3600'
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
config.action_dispatch.show_exceptions = false
config.action_controller.allow_forgery_protection = false
config.action_mailer.default_url_options = {
:host => '127.0.0.1',
:port => 3000
}
config.action_mailer.delivery_method = :test
config.active_support.test_order = :random
config.active_support.deprecation = :stderr
堆栈跟踪:
1) UserController validates user
Failure/Error: put :update, { id: user.id }
NoMethodError:
undefined method `cache' for nil:NilClass
# ~/.rvm/gems/ruby-2.2.2/gems/actionview-4.2.5.1/lib/action_view/template/resolver.rb:151:in `cached'
# ~/.rvm/gems/ruby-2.2.2/gems/actionview-4.2.5.1/lib/action_view/template/resolver.rb:121:in `find_all_anywhere'
# ~/.rvm/gems/ruby-2.2.2/gems/actionview-4.2.5.1/lib/action_view/path_set.rb:68:in `block (2 levels) in _find_all'
# ~/.rvm/gems/ruby-2.2.2/gems/actionview-4.2.5.1/lib/action_view/path_set.rb:66:in `each'
# ~/.rvm/gems/ruby-2.2.2/gems/actionview-4.2.5.1/lib/action_view/path_set.rb:66:in `block in _find_all'
# ~/.rvm/gems/ruby-2.2.2/gems/actionview-4.2.5.1/lib/action_view/path_set.rb:65:in `each'
# ~/.rvm/gems/ruby-2.2.2/gems/actionview-4.2.5.1/lib/action_view/path_set.rb:65:in `_find_all'
# ~/.rvm/gems/ruby-2.2.2/gems/actionview-4.2.5.1/lib/action_view/path_set.rb:50:in `find_file'
# ~/.rvm/gems/ruby-2.2.2/gems/actionview-4.2.5.1/lib/action_view/lookup_context.rb:126:in `find_file'
# ~/.rvm/gems/ruby-2.2.2/gems/actionview-4.2.5.1/lib/action_view/renderer/abstract_renderer.rb:18:in `find_file'
# ~/.rvm/gems/ruby-2.2.2/gems/actionview-4.2.5.1/lib/action_view/renderer/template_renderer.rb:32:in `block in determine_template'
# ~/.rvm/gems/ruby-2.2.2/gems/actionview-4.2.5.1/lib/action_view/lookup_context.rb:147:in `with_fallbacks'
# ~/.rvm/gems/ruby-2.2.2/gems/actionview-4.2.5.1/lib/action_view/renderer/abstract_renderer.rb:18:in `with_fallbacks'
# ~/.rvm/gems/ruby-2.2.2/gems/actionview-4.2.5.1/lib/action_view/renderer/template_renderer.rb:32:in `determine_template'
# ~/.rvm/gems/ruby-2.2.2/gems/actionview-4.2.5.1/lib/action_view/renderer/template_renderer.rb:8:in `render'
# ~/.rvm/gems/ruby-2.2.2/gems/actionview-4.2.5.1/lib/action_view/renderer/renderer.rb:42:in `render_template'
# ~/.rvm/gems/ruby-2.2.2/gems/actionview-4.2.5.1/lib/action_view/renderer/renderer.rb:23:in `render'
# ~/.rvm/gems/ruby-2.2.2/gems/actionview-4.2.5.1/lib/action_view/rendering.rb:100:in `_render_template'
# ~/.rvm/gems/ruby-2.2.2/gems/actionpack-4.2.5.1/lib/action_controller/metal/streaming.rb:217:in `_render_template'
# ~/.rvm/gems/ruby-2.2.2/gems/actionview-4.2.5.1/lib/action_view/rendering.rb:83:in `render_to_body'
# ~/.rvm/gems/ruby-2.2.2/gems/actionpack-4.2.5.1/lib/action_controller/metal/rendering.rb:32:in `render_to_body'
# ~/.rvm/gems/ruby-2.2.2/gems/actionpack-4.2.5.1/lib/action_controller/metal/renderers.rb:37:in `render_to_body'
# ~/.rvm/gems/ruby-2.2.2/gems/actionpack-4.2.5.1/lib/abstract_controller/rendering.rb:25:in `render'
# ~/.rvm/gems/ruby-2.2.2/gems/actionpack-4.2.5.1/lib/action_controller/metal/rendering.rb:16:in `render'
# ~/.rvm/gems/ruby-2.2.2/gems/actionpack-4.2.5.1/lib/action_controller/metal/instrumentation.rb:44:in `block (2 levels) in render'
# ~/.rvm/gems/ruby-2.2.2/gems/activesupport-4.2.5.1/lib/active_support/core_ext/benchmark.rb:12:in `block in ms'
# ~/.rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/benchmark.rb:303:in `realtime'
# ~/.rvm/gems/ruby-2.2.2/gems/activesupport-4.2.5.1/lib/active_support/core_ext/benchmark.rb:12:in `ms'
# ~/.rvm/gems/ruby-2.2.2/gems/actionpack-4.2.5.1/lib/action_controller/metal/instrumentation.rb:44:in `block in render'
# ~/.rvm/gems/ruby-2.2.2/gems/actionpack-4.2.5.1/lib/action_controller/metal/instrumentation.rb:87:in `cleanup_view_runtime'
# ~/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.5.1/lib/active_record/railties/controller_runtime.rb:25:in `cleanup_view_runtime'
# ~/.rvm/gems/ruby-2.2.2/gems/actionpack-4.2.5.1/lib/action_controller/metal/instrumentation.rb:43:in `render'
这是一个 rspec/rspec-rails issue。
您可以升级到rspec-rails-3.4.1 来修复它。除非你的 Gemfile 中有 hard-coded rspec-rails 的版本,运行:
bundle update rspec-rails rspec
应该可以解决问题。
从rails4.2.5
升级到最近发布的4.2.5.1
时,我遇到了这个错误。此错误仅存在于具有呈现无效状态的 before_filter
的规格,例如 render file: "public/422", status: :unauthorized
。 ruby-2.2.2 和 ruby-2.3.0
错误存在于 action_view 解析器方法中,暗示 @cache
值为 nil。但是,在 initialize
方法中它应该被实例化: @cache = Cache.new
我仍在研究可重现的样本,但到目前为止我不知道 @cache
怎么可能是零。
这些是在我的 test.rb
环境中设置的配置变量
config.cache_classes = true
config.eager_load = false
config.serve_static_files = true
config.static_cache_control = 'public, max-age=3600'
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
config.action_dispatch.show_exceptions = false
config.action_controller.allow_forgery_protection = false
config.action_mailer.default_url_options = {
:host => '127.0.0.1',
:port => 3000
}
config.action_mailer.delivery_method = :test
config.active_support.test_order = :random
config.active_support.deprecation = :stderr
堆栈跟踪:
1) UserController validates user
Failure/Error: put :update, { id: user.id }
NoMethodError:
undefined method `cache' for nil:NilClass
# ~/.rvm/gems/ruby-2.2.2/gems/actionview-4.2.5.1/lib/action_view/template/resolver.rb:151:in `cached'
# ~/.rvm/gems/ruby-2.2.2/gems/actionview-4.2.5.1/lib/action_view/template/resolver.rb:121:in `find_all_anywhere'
# ~/.rvm/gems/ruby-2.2.2/gems/actionview-4.2.5.1/lib/action_view/path_set.rb:68:in `block (2 levels) in _find_all'
# ~/.rvm/gems/ruby-2.2.2/gems/actionview-4.2.5.1/lib/action_view/path_set.rb:66:in `each'
# ~/.rvm/gems/ruby-2.2.2/gems/actionview-4.2.5.1/lib/action_view/path_set.rb:66:in `block in _find_all'
# ~/.rvm/gems/ruby-2.2.2/gems/actionview-4.2.5.1/lib/action_view/path_set.rb:65:in `each'
# ~/.rvm/gems/ruby-2.2.2/gems/actionview-4.2.5.1/lib/action_view/path_set.rb:65:in `_find_all'
# ~/.rvm/gems/ruby-2.2.2/gems/actionview-4.2.5.1/lib/action_view/path_set.rb:50:in `find_file'
# ~/.rvm/gems/ruby-2.2.2/gems/actionview-4.2.5.1/lib/action_view/lookup_context.rb:126:in `find_file'
# ~/.rvm/gems/ruby-2.2.2/gems/actionview-4.2.5.1/lib/action_view/renderer/abstract_renderer.rb:18:in `find_file'
# ~/.rvm/gems/ruby-2.2.2/gems/actionview-4.2.5.1/lib/action_view/renderer/template_renderer.rb:32:in `block in determine_template'
# ~/.rvm/gems/ruby-2.2.2/gems/actionview-4.2.5.1/lib/action_view/lookup_context.rb:147:in `with_fallbacks'
# ~/.rvm/gems/ruby-2.2.2/gems/actionview-4.2.5.1/lib/action_view/renderer/abstract_renderer.rb:18:in `with_fallbacks'
# ~/.rvm/gems/ruby-2.2.2/gems/actionview-4.2.5.1/lib/action_view/renderer/template_renderer.rb:32:in `determine_template'
# ~/.rvm/gems/ruby-2.2.2/gems/actionview-4.2.5.1/lib/action_view/renderer/template_renderer.rb:8:in `render'
# ~/.rvm/gems/ruby-2.2.2/gems/actionview-4.2.5.1/lib/action_view/renderer/renderer.rb:42:in `render_template'
# ~/.rvm/gems/ruby-2.2.2/gems/actionview-4.2.5.1/lib/action_view/renderer/renderer.rb:23:in `render'
# ~/.rvm/gems/ruby-2.2.2/gems/actionview-4.2.5.1/lib/action_view/rendering.rb:100:in `_render_template'
# ~/.rvm/gems/ruby-2.2.2/gems/actionpack-4.2.5.1/lib/action_controller/metal/streaming.rb:217:in `_render_template'
# ~/.rvm/gems/ruby-2.2.2/gems/actionview-4.2.5.1/lib/action_view/rendering.rb:83:in `render_to_body'
# ~/.rvm/gems/ruby-2.2.2/gems/actionpack-4.2.5.1/lib/action_controller/metal/rendering.rb:32:in `render_to_body'
# ~/.rvm/gems/ruby-2.2.2/gems/actionpack-4.2.5.1/lib/action_controller/metal/renderers.rb:37:in `render_to_body'
# ~/.rvm/gems/ruby-2.2.2/gems/actionpack-4.2.5.1/lib/abstract_controller/rendering.rb:25:in `render'
# ~/.rvm/gems/ruby-2.2.2/gems/actionpack-4.2.5.1/lib/action_controller/metal/rendering.rb:16:in `render'
# ~/.rvm/gems/ruby-2.2.2/gems/actionpack-4.2.5.1/lib/action_controller/metal/instrumentation.rb:44:in `block (2 levels) in render'
# ~/.rvm/gems/ruby-2.2.2/gems/activesupport-4.2.5.1/lib/active_support/core_ext/benchmark.rb:12:in `block in ms'
# ~/.rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/benchmark.rb:303:in `realtime'
# ~/.rvm/gems/ruby-2.2.2/gems/activesupport-4.2.5.1/lib/active_support/core_ext/benchmark.rb:12:in `ms'
# ~/.rvm/gems/ruby-2.2.2/gems/actionpack-4.2.5.1/lib/action_controller/metal/instrumentation.rb:44:in `block in render'
# ~/.rvm/gems/ruby-2.2.2/gems/actionpack-4.2.5.1/lib/action_controller/metal/instrumentation.rb:87:in `cleanup_view_runtime'
# ~/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.5.1/lib/active_record/railties/controller_runtime.rb:25:in `cleanup_view_runtime'
# ~/.rvm/gems/ruby-2.2.2/gems/actionpack-4.2.5.1/lib/action_controller/metal/instrumentation.rb:43:in `render'
这是一个 rspec/rspec-rails issue。
您可以升级到rspec-rails-3.4.1 来修复它。除非你的 Gemfile 中有 hard-coded rspec-rails 的版本,运行:
bundle update rspec-rails rspec
应该可以解决问题。