Update 2/5/07: I’ve since discovered five plugins that address this very problem with slightly different approaches (the latter two store a permalink in the table, good for mutable titles):
Obie’s recent post on search engine friendly URL’s in Ruby on Rails 1.2 and greater couldn’t have been more timely. I was about to tackle search engine friendly URL’s on my little local san francisco bay area boating classifieds site and after reading his blog post, 15 minutes later it was done. Here’s the old URL structure:
and the new (longer for humans but much better for SEO):
The most important thing is that the URL’s are backwards compatible because everything after the ID is ignored which is key for pages that are already in the search engines!
script/plugin install http://svn.techno-weenie.net/projects/plugins/permalink_fu
Then in my topic.rb model object I do:
and I double checked to make sure that the views always call link_to passing the model object rather than the ID (so that the to_param method has access to the id and the title). Fortunately beast.caboo.se (which is what I based my site on) make heavy use of named routes:
After that I was pretty much done but I had some really long URL’s so I truncated the title to the first 5 words by changing