I have List objects which are shown like this:
http://www.mysite.com/lists/123
Where 123 is the id of the list. What I would like to do is add the title of the list the url so it it more informative(for google or whatever). So I would like it to look like:
http://www.mysite.com/lists/123/title-of-list-number-123
How do you go about adding to a url like this? If you just enter:
http://www.mysite.com/lists/123 w/o the title, should it find the title and then redirect to a new route?
If you want to keep your find-calls as they are (by id), you could do the opposite of what mplacona suggested:
With this, your find(params[:id]) will work because it’ll convert the string to an integer (can only succeed if the number is in the beginning of the string). So this is will actually work:
and will be the same as
Read more about this and other ways to accomplish this here: http://gregmoreno.ca/how-to-create-google-friendly-urls-in-rails/
The parameterize will automatically convert the string to a “pretty” url. Read more here: http://api.rubyonrails.org/classes/ActiveSupport/CoreExtensions/String/Inflections.html#M001367
If you want a bit more functionality, I’ll suggest friendly_id aswell.