簡體   English   中英

如何縮短Rails中的S3 \\ Paperclip URL

[英]How to shorten S3\Paperclip URL in Rails

我們正試圖在Twitter提要中安裝視頻鏈接,甚至使用簡短的DNS,它需要更短:

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

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

它似乎不是你在路線上可以做的任何東西,因為它在S3處就是這樣。

任何好主意都贊賞。

我在https://github.com/philnash/bitly使用了bitly gem

超級易於配置和使用!

添加到gem文件

gem 'bitly'

運行捆綁器

bundle

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

創建config / initializers / 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應用程序並開始使用gem如下

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)

我在我的模型中使用它來更新我的網站上的twitter,所以我有一個after_save調用如下

after_save :update_twitter, :on => :new

def update_twitter
  // code goes here
end 

希望有所幫助..

你可以試試'不久'的寶石。 它支持相當多的不同網址縮短服務。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM