开发者

word constraints in routing

match '/posts/:id/:title' => 'posts#show', :as => :slug
resources :posts

I don't want slug_path to match some words as title parameter. For example:

posts/5/edit

"edit" is making trou开发者_Go百科ble. I want to restrict this word.


If you're only worried about the standard routes interfering (like edit), simply put your match statement after your resources :posts. That way, the match statement will only catch anything that the resources statement didn't know how to handle.


You can also use a regular expression as a constraint to limit what :title can match. Another option would also be to make your URL more explicit - this would also avoid confusion with the default restful actions:

match '/posts/:id/title/:title' => 'posts#show', :as => :slug
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜