简体   繁体   中英

Rails: 'match' function in routes.rb escaping slashes in url

I am new to ruby and rails. Here in routes.rb i have added the following line:

match 'check/' => "home#index"

When i hit url with server running on port 3000:

localhost:3000/check/

it works fine, but if i give url

localhost:3000/////////////////check////////////////////

it also works fine which should not be the case. With url

localhost:3000/////////////check////d//////

it says

No route matches [GET] "/check/d"

It means it is escaping slashes, why this is happening and how to resolve it. Also help me to know if we can make urls using regular exressions on rails.

Regarding regular expressions in routes:

match '/:id' => 'posts#show', :constraints => {:id => /^\d/}

Will put a constraint on the id to be only digits.

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.

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