问题描述
undefined method `find_script_name' for nil:NilClass
在这种情况下,正在使用的路由是 root_path
但也为许多其他路由获取了这个! routes.rb
如下(在删除所有其他路由定义后尝试这样)
Rails.application.routes.draw do
root 'home#index'
end
我在网上找到的唯一相关内容是 this commit。有人知道可能出了什么问题吗?
我正在运行 ruby 2.7.2
解决方法
它看起来像是当前版本的 rails 6.1 中的一个错误
https://github.com/rails/rails/issues/42218
当前的修复是在视图内的所有路径辅助调用前加上:
Rails.application.routes.url_helpers.
所以 session_path 变成了 Rails.application.routes.url_helpers.session_path