以下是Rails服务器日志的两个示例,用于在仅更改
Ruby版本时遇到的错误.
Ruby 2.4.2,Rails 5.1.4,Puma 3.11.0:
NoMethodError - undefined method `recent' for #<Event:0x00007f08507bf8b8>: path/to/show.html.haml:50:in `block in _path_to_show_html_haml___4224769623360811234_28796540' path/to/show.html.haml:30:in `_path_to_show_html_haml___4224769623360811234_28796540'
Ruby 2.5.0,Puma 3.11.0:
NoMethodError - undefined method `recent' for #<Event:0x00007f8ccc1b9508>:
如何在Rails日志中重新启用堆栈跟踪?看起来没有办法查看要查看的文件/行号.
为了帮助调查,我将其添加到我的ApplicationController中:
rescue_from Exception do |exception| byebug 1+1 end
Ruby 2.4.2
(byebug) exception.backtrace # A very large array of paths appears
Ruby 2.5.0
(byebug) exception.backtrace nil
解决方法
Gemfile中的binding_of_caller gem已过期.我从0.7.3升级到0.8.0,问题就消失了.