简体   繁体   English

Ruby on Rails自定义Rails资源路由错误页面

[英]Ruby on Rails Custom Rails Resource Routing Error Pages

I would like to route all broken site links for a rails resource to a particular custom error page and all other broken links to another custom error page. 我想将Rails资源的所有损坏的站点链接路由到特定的自定义错误页面,将所有其他损坏的链接路由到另一个自定义错误页面。 For example: 例如:

/locations/wrong-location - Invalid location error page / locations /错误位置-无效的位置错误页面

/products/wrong-product - Invalid product error page / products /错误产品-无效的产品错误页面

Does anyone know how to do this in Rails 3.2? 有谁知道如何在Rails 3.2中做到这一点?

You want to use a catch-all in your routes.rb : 您想在routes.rb使用routes.rb

match 'locations/*other', to: 'locations#wrong-location'

or in Rails 4 或在Rails 4中

match 'locations/*other', to: 'locations#wrong-location`, via: :all

And then just set up the controller and view. 然后只需设置控制器并查看。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM