开发者

Rails 3 resource without prefix

I have a resource 'Post' in my app. The default routes for resources :posts gives urls like /posts/:id. Is 开发者_如何学Cit possible to remove 'posts' from the route, and just have /:id instead?


You can use :path to remove the '/posts' bit...

resources :posts, :path => "/"

Just be aware that this could confuse other routes which are defined below it in your routes file. It's best to have this kind of catch-all route at the bottom for this reason.


You can add a custom route for this (make sure to put it at the bottom of your routes.rb file, otherwise it'll match non-posts routes too)

match ':id' => 'posts#show'
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜