【发布时间】:2012-11-14 08:27:23
【问题描述】:
又是新手问题...我已经有了以下代码,用于使用 Bitly 缩短链接。
def bitly_links(url)
bitly ||= begin
Bitly.use_api_version_3
Bitly.new('username', 'key')
bitly.shorten(url)
end
end
这次我想做的是在评论创建后搜索并缩短评论中的所有链接。这与这篇博文 Using bitly in rails 3 类似,但由于使用了 for 循环而不是 do 循环,因此有点令人困惑。 ..结束块。另外,我注意到该方法甚至没有被调用。
网站中的示例评论:
嘿,你应该看看帖子 http://vox4life.blogspot.com/2012/11/4Life-2012-Growth-is-strong.html 和这个.. http://vox4life.blogspot.com/2012/11/dengue-outbreak-peoples-journal.html 还有这个 http://vox4life.blogspot.com/2012/02/transfer-factor-immunotherapy.html
会变成:
嘿,你应该看看帖子http://bit.ly/ZHdLTa和这个..http://bit.ly/TZ6Nrj还有这个http://bit.ly/ZrnWMj
提前谢谢你。
Similar question to this,但在 Java 中
【问题讨论】:
标签: ruby-on-rails hyperlink url-shortener