如何缩短Rails中的S3 \ Paperclip URL

时间:2014-01-23 00:42:41

标签: ruby-on-rails amazon-s3 paperclip

我们正在尝试在Twitter Feed中添加视频链接,即使使用简短的DNS,也需要更短的时间:

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

我想您可以将回形针附件名称从视频更改为v并购买几个字符,但有没有人想出更好的方法来缩短Rails中的S3 \ Paperclip样式链接?

这似乎不是你在路线上可以做的任何事情,因为此时它在S3。

任何好主意都赞赏。

2 个答案:

答案 0 :(得分:2)

我在https://github.com/philnash/bitly

使用了有点宝石

超级易于配置和使用!

添加到gem文件

gem 'bitly'

运行bundler

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 

希望有所帮助..

答案 1 :(得分:0)

你可以试试'不久'的宝石。它支持相当多的不同网址缩短服务。

相关问题