2014-01-23 69 views
0

我們正在努力適應Twitter的飼料,甚至與短DNS鏈接到視頻,它需要更短:如何縮短S3 回形針URL Rails中

http://domain.com/videos/164/original.mp4

我想你可以改變回形針附件名稱從視頻到v和購買幾個字符,但有人想出了一個更好的方法來縮短Rails中的S3 \ Paperclip樣式鏈接?

這似乎不是你在路線上可以做的任何事情,因爲它現在在S3。

任何好主意讚賞。

+0

根據https://support.twitter.com/articles/78124-posting-links-in-a-tweet –

+0

,我們希望使用Twitter的t.co簡稱縮短您的鏈接,無論您的網址是什麼在幾個不同的地方使用,但電子郵件等。想弄清楚鐵路解決方案。 – ricric85

回答

2

我使用bitly寶石在https://github.com/philnash/bitly

超級容易配置和使用!

添加到寶石文件

gem 'bitly' 

運行捆綁

bundle 

在創建一個帳戶[https://bitly.com/][1]

創建配置/初始化/ bitly.rb並添加配置信息

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 

重新啓動您的Rails應用程序,並開始使用的寶石作爲跟隨

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) 

我用它在我的模型,從我的網站更新微博,所以我有一個after_save的通話如下

after_save :update_twitter, :on => :new 

def update_twitter 
    // code goes here 
end 

希望有所幫助。

+0

非常感謝,我需要將config.api_key更改爲config.access_token – Defoncesko