We are trying to fit link to video in Twitter feed and even with short DNS, it needs to be shorter:
http://domain.com/videos/164/original.mp4
I guess you could change the paperclip attachment name from videos to just v and buy a few chars but has anyone came up with a better way to shorten S3\\Paperclip style links in Rails?
It doesn't seem to be anything you can do in routes as it's at S3 at this point.
Any good idea appreciated.
I use the bitly gem at https://github.com/philnash/bitly
super easy to configure and use!
Add to gem file
gem 'bitly'
run bundler
bundle
create an account at [https://bitly.com/][1]
create config/initializers/bitly.rb and add the configuration info
Bitly.configure do |config|
config.api_version = 3
config.login = "Bitly_Username" # <--- from the account you created above
config.api_key = "API_KEY" # <--- from the account you created above
end
restart your rails app and start using the gem as follow
bitlink = Bitly.client
bitlink = bitly.shorten("http://www.howtomovetomaui.com/blogs/super_long_link_page_history_one/this_will_never_stop/ET-want-to-go-home.html", :history => 1)
I use it in my model to update twitter from my site so I have a after_save call as follow
after_save :update_twitter, :on => :new
def update_twitter
// code goes here
end
Hope that helps..
You might try the 'shortly' gem. It supports quite a few different url shortening services.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.