Monday, January 14, 2013

Get original urls from short urls created by services like bitly, tinyurl, twitter etc using ruby and open-uri

Pretty straight forward it is. Writing it here coz i couldn't find anything like this explained for ruby, found a lotta blogs for python though.

So i thought of explaining it here. So here goes. Sometimes we come across urls like http://bit.ly/y2uy321oy3 which can be for any website. There's this simple way to retrieve its original url.

The not so famous before_remove/before_add & after_remove/after_add callbacks.

Well, this is another rails feature and a quite nice one which is not documented properly.

While using has_many :through associations, we can use before_remove, before_add, after_remove, after_add callbacks.