繁体   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