Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何从RoutingErrorRails 3.2 应用程序中解救,例如重定向到root_path?
RoutingError
root_path
我想不出你想从 RoutingError 中解救出来的任何情况。
如果您希望所有未指定的路由重定向到某个特定操作(例如,对于自定义“未找到”错误),您可以使routes.rb文件中的最后一个路由匹配任何内容并指向那里:
routes.rb
match "*path" => 'some_controller#some_action'
按顺序尝试路由并使用第一个匹配的路由,因此只要它保持在最后,当且仅当没有其他路由与请求的路径匹配时才会使用它。