Custom slugs for Rails URLs done right

Amin Shah Gilani
HackerNoon.com
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:

  1. Vanity URLs, e.g. trying to open a user’s profile at /u/amingilani
  2. 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.

--

--

Amin Shah Gilani
HackerNoon.com

Founder. Developer. Spaces over tabs. Atom over your favorite X.