Implementing twitter-like hashtag on rails

后端 未结 3 1836
终归单人心
终归单人心 2021-01-30 11:45

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

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

相关标签:
3条回答
  • 2021-01-30 12:17

    For late-comers…

    I have written a simple gem for precisely for this:
    https://github.com/ralovely/simple_hashtag

    Give feedback or contribute if you feel like it.

    0 讨论(0)
  • 2021-01-30 12:17

    ActsAsTaggableOn should work fine if you are not too worried about scaling. It keeps track of your actual tags by ActsAsTaggableOn::Tag, and keeps track of the many-to-many relationship to your posts by ActsAsTaggableOn::Tagging. It also uses polymorphic association in ActsAsTaggableOn::Tagging so you can tag in different namespaces.

    0 讨论(0)
  • 2021-01-30 12:23

    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).

    0 讨论(0)
提交回复
热议问题