Shortened link with Bitly API, how do I remove the 'http://'?
I'm currently using the ruby-bitly gem to shorten links in a Rails app; however, the result has an "http://" in front of the bit.ly link. This is not friendly for tweets/other length sensitive posts. How do I automatically remove that?
Link controller action:
def shorten_with_bitly(url)
link = Link.find(params[:id])
bitly = Bitly.shorten(url, "MY_ID", "MY_API_KEY")
bitly.url = link.shortened_link开发者_运维技巧
link.save
end
Thank you very much for your help!!!
Use gsub, for instance:
"http://google.com".gsub("http://", "")
or use slice:
"http://google.com".slice!(0..6)
Keep in mind that the ! will modify the original string, not just give you a modified copy.
精彩评论