how to implement a short url like urls in twitter?
If there is a long url, i want to generate a short url like those in twitter, is there some way to implement in ruby? Thank you in advance. The easiest way is to: keep a database of all URLs when you insert a new URL into the database, find out the id of the auto-incrementing integer primary key. encode that integer into base 36 or 62 (digits + lowercase alpha or digits + mixed-case alpha). Voila! You have a short url! Encoding to base 36/decoding from base 36 is simple in Ruby: 12341235.to_s(36) #=> "7cik3" "7cik3".to_i(36) #=> 12341235 Encoding to base 62 is a bit tricker. Here's one way to