18

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

tipbis
  • 357
  • 3
  • 9
  • Do you have a particular question you're struggling with? – carols10cents Mar 23 '11 at 13:34
  • This question really isn't clear. What part of this implementation are you struggling with? – Tim Post Mar 23 '11 at 13:36
  • This is interesting. I'm curious about various approaches to doing this - so far, it seems like acts-as-taggable-on is the only encouraged way. Also, is there a way to have these hashtags, but have them be like mentions on Facebook? In a post on Facebook, I could say "Good thing Danny and I went to Place X" and Danny, the name of the user, would be highlighted and linked... – dmonopoly Jul 30 '11 at 13:51

3 Answers3

12

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

Will Richardson
  • 7,780
  • 7
  • 42
  • 56
Adam Rubin
  • 777
  • 1
  • 7
  • 16
  • 3
    For anyone else looking at this the url has moved to https://github.com/twitter/twitter-text-rb – Dom Dec 23 '12 at 04:55
  • And has moved again to https://github.com/twitter/twitter-text, with the Ruby section here: https://github.com/twitter/twitter-text/tree/master/rb – littleforest Jun 29 '16 at 17:41
3

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.

ralovely
  • 81
  • 4
1

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.

etang
  • 730
  • 8
  • 23