How do I define a routes match any things exclude string ( like '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.
Utilizing the fact that routes are matched in the order they are defined in routes.rb
, this is a good approach to do it:
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.
If string
is not websocket
on the other hand, then it will match the second line.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.