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:
or use slice:
Keep in mind that the ! will modify the original string, not just give you a modified copy.