Reputation: 13
How can i customize restful route urls to friendly urls like stackoverflow ?
i have stackoverflow.com/questions/424/
and i want to have stackoverflow.com/questions/424/title-of-the-page
Upvotes: 0
Views: 121
Reputation: 13
map.resources :questions
map.friendly 'questions/:id/:title', :controller => 'questions', :action => 'show'
These are my final customizations. Any better ideas ?
Upvotes: 1
Reputation: 6872
If there's only one controller you want to do this with, the simplest solution would probably be to add a route with an ignored parameter, like so:
# config/routes.rb
map.connect 'questions/:id/:ignored', :controller => 'questions', :action => 'show'
Make sure you put this before the default routes at the bottom of that file. Or, even better, comment them out if you're using named routes and resources (as suggested in the auto-generated comments).
Upvotes: 0
Reputation: 39325
I'd start by looking at the capabilities of something like friendly_id and see if those aren't what you're looking for...
Upvotes: 0
Reputation: 479
StackOverflow ignores the string second parameter at request processing time. At URL construction time it adds it for humans and (probably) SEO.
Upvotes: 0