routes - rerouting nested resource in Rails -


i have in routes:

resources :users   resources :posts end 

it creates show path /users/:user_id/posts/:post_id

great. if types /users/:user_id/post/:post_id (mind singular /post , not /posts) 404. want 302 redirect .../post/:post_id ../posts/:post_id in routes. how?

you may able achieve using following in routes config.

get '/users/:user_id/post/:post_id', to: redirect('/users/%{user_id}/posts/%{post_id}') 

more info here: http://guides.rubyonrails.org/routing.html section: 3.12 redirection


Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)

Google AdWords and AdSense - A Dynamic Small Business Marketing Duo