1

I would like to display a shortened URL besides the content items on my site for ease of sharing.

What would be the most efficient way of doing so, and are there any suitable gems / libraries?

I am using rails on a mongodb/mongoid stack

enter image description here

meow
  • 27,476
  • 33
  • 116
  • 177
  • Check this out http://stackoverflow.com/questions/6338870/how-to-implement-a-short-url-like-urls-in-twitter.. – RameshVel Oct 20 '11 at 08:13

2 Answers2

1

should be simple enough (regardless if you are on Mongo / MySQL or anything else). what you need is a small collection (mongo if i may) that holds some kind of an MD5 hash of the real url you are after and the real url itself, for example:

ShortLink.create(:hash_link => Digest::MD5.hexdigest(resource_url(@resource)), :real_link => resource_url(@resource))

I suggest adding another route that catches those like this:

match "l/:key", "ShortLinks#show"

should be easy.

Elad Meidar
  • 774
  • 6
  • 11
0

I think you can use bitly gem to shorten your URL.

The following link helps you to configure bitly:

http://www.marketingformavens.com/blog/url-shortening-bitly-ruby-on-rails

Abhilash M A
  • 564
  • 5
  • 12