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'
精彩评论