我们正在尝试在Twitter feed中适配视频链接,即使使用短DNS,它也需要更短:
http://domain.com/videos/164/original.mp4
我猜你可以把回形针附件的名字从视频改成v,然后买几个字符,但是有没有人想出一个更好的方法来缩短Rails中的S3\回形针样式的链接?
这似乎不是你可以在路由中做的任何事情,因为它是在S3中。
任何好的想法都很感谢。
发布于 2014-01-24 01:59:54
我在https://github.com/philnash/bitly用的是bitly gem
非常容易配置和使用!
添加到gem文件
gem 'bitly'运行bundler
bundle在https://bitly.com/上创建帐户
创建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 希望这会有帮助..。
发布于 2014-01-23 13:50:22
你可以试试“shortly”这个宝石。它支持相当多不同的网址缩短服务。
https://stackoverflow.com/questions/21297152
复制相似问题