Custom slugs for Rails URLs done right
Published in
2 min readJul 14, 2017
--
I’ve seen a lot of examples of this online, and it took a while for me to get it right, so I decided to document it.
The two cases I’ve used this for:
- Vanity URLs, e.g. trying to open a user’s profile at
/u/amingilani
- Obfuscated URLs, e.g. trying to make the URL difficult to guess such as
/transactions/601585f7–0f4a-41e8-bd04-b2eb24262fb4
Both cases differ only by the fact that the slug is randomly generated in the latter.