在 rails 上实现类似 twitter 的 hashtag [英] Implementing twitter-like hashtag on rails

查看:45
本文介绍了在 rails 上实现类似 twitter 的 hashtag的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的应用中实现类似 twitter 的主题标签.

I'm want to implement twitter-like hashtag on my app.

假设我有用户输入文本区域我要从 #paris 来到 #london",然后我想构建主题标签的标签云.

Let's say I have user input to a text area "I'm coming to #london from #paris" then I want to build tag cloud of the hashtags.

我正在考虑使用作为可标记的行为.所以我从后端的文本中找到我所有的主题标签,然后将其保存到标签字段.

I'm thinking of using acts-as-taggable-on. So I find all of my hashtags from the text in the backend, then save it to tag field.

有人有这方面的经验愿意分享吗?谢谢.

Anyone has experience on this they would like to share? Thanks.

推荐答案

是的,ActsAsTaggableOn 应该没问题.正如@etang 所暗示的,这是一颗沉重的宝石,但它完成了工作.如果您正在寻找一种从文本中提取标签的简单方法,您可能需要查看 https://github.com/twitter/twitter-text-rb.它有一些不错的正则表达式,可以为您节省一些时间.

Yes, ActsAsTaggableOn should be fine. As @etang alluded to, it's a heavy gem, but it gets the job done. If you're looking for a simple way to extract tags from text, you may want to look at https://github.com/twitter/twitter-text-rb. It has some nice regexps that may save you some time.

Twitter::Extractor.extract_hashtags("my #favorite #site is http://foo.com/home#boo")

这将返回收藏夹"和站点",但不会返回嘘"(正如预期的那样).

That would return "favorite" and "site" but not "boo" (as would be expected).

这篇关于在 rails 上实现类似 twitter 的 hashtag的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆