Don't roll your own slug code, use FriendlyId
This finding was a pleasant surprise. For years, I've been writing the same kind of boilerplate code to override to_param
on my model classes and generate unique slugs. Turns out there's a really well-written library that does that, with some worthwhile additional functionality. Check out FriendlyId for easy slug generation and even the ability to preserve history of slugs after changes, so that it's possible to do 301 redirects with just a couple lines of code.