Dealing with permalinks in Rails
by Emilien Taque
When you want to improve your SEO karma, you have to play with your urls. You can use norman/friendly_id, but you can also do it yourself, it’s quite simple: just rewrite to_param method.
We can go further by creating a column for the permalink and using a hook to fill it:
On the controller side, it remains the same thanks to this Ruby behaviour:
More interesting, we can avoid duplicate content by redirecting urls with a bad permalink:
Update
Thanks to Henryk Nye, I’ve improved my :redirect_if_moved method (maybe should I rename it :redirect_if_better).
Direct quote:
Using
:overwrite_paramswill ensure any additional parameters are unchanged.
Have SEO fun!
Comments
It doesn’t look like you’re ever calling your redirect_if_moved method.
Mmm yes, it was unclear. Should be better now.
Thanks Emilien! I’ve tweaked your solution a bit and posted it here: http://patrickberkeley.github.com/rails/rails-3-permalinks/. I think you need to keep the normal render in you controller’s show action if you want to display different formats.