[英]Ruby on Rails - Regular expression for error routes
How do I define a routes match any things exclude string ( like 'websocket' )? 如何定义与任何排除字符串(例如'websocket')的内容匹配的路由?
Thanks! 谢谢!
Based on the comments, it sounds like you want to match /websocket
to a specific action and everything else to an 404 error page. 根据注释,听起来您想将
/websocket
与特定操作进行匹配,将其他所有内容与404错误页面进行匹配。
Utilizing the fact that routes are matched in the order they are defined in routes.rb
, this is a good approach to do it: 利用路由按照在
routes.rb
中定义的顺序进行匹配的事实,这是一种很好的方法:
match '/websocket' => 'controller#action'
match '/:slug' => "errors#show", :code => 404, :via => [:get]
When a request /string
comes, the routing subsystem will first try to match it to the first line, and if string
is equal to websocket
then the match is successful and no more routes will be matched. 当请求
/string
到来时,路由子系统将首先尝试将其与第一行匹配,如果string
等于websocket
则匹配成功,并且将不再匹配任何路由。
If string
is not websocket
on the other hand, then it will match the second line. 如果
string
不是websocket
,则它将与第二行匹配。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.