Best way to generate bit.ly or twitpic style ids?

562 Views Asked by At

For a personal project I'm working on, I'd like to generate ids for objects on my website in the same style as sites like bit.ly and twitpic. Sending users to example.com/4gwv9k would let me get the item with id 9gwv9k. Is this simply a question of auto-incrementing on a base-36 scheme or is there some underlying, non-incrementing magic going on?

This is all being done in Rails, so any gem support would be welcome as well.

2

There are 2 best solutions below

0
On BEST ANSWER

Here's an example on I did it in Sinatra.

https://github.com/chrisledet/shorty_url

1
On

You may use autoincrement integer translated to 62 based number (26 small letters + 26 cap letters + 10 digits)