Question

The title says it all really. I am looking for a rails gem to search by hashtags and reply to posts by tagging users with an @ sign just like how Twitter does it. I do not want these to go to Twitter or pull from Twitter. I want them to be able to only use hashtags with certain words. I was going to use Acts_As_Taggable_On, but it looks like you tag others with skills and other types of tagging. Can this gem actually do the things I am needing and if so where would I find out that information. I went over the Rails Cast and readme and it doesn't seem like it works that way. Thanks for your help.

Was it helpful?

Solution

I have been developing a similar thing some time ago and i don't think that there are such gems available for the things you need. It's too complex to be handled by a gem. If you want it to work in a similar manner to twitter, here is how i would do that:

1. Posts tagging

Let's say we have a Post model with body param. First, to add a tagging functionality, we should enable acts_as_taggable_on gem for our Post model which will give us few methods, like tag_list for instance. When that's ready, we need to somehow obtain hashtags provided in a body field and save them as tag_list.

My solution for that was to use a twitter-text-rb gem. Using a following code snippet, you can extract hash tags from a body field and save them to tag_list.

def extract_tags(post)
  include Twitter::Extractor
  tags = extract_hashtags(post.body)
  post.update_attribute(:tag_list, tags)
end

And from that point, we're able to search for posts tagged with certain tags using acts_as_taggable_on built-in methods Post.tagged_with('#first')

2. Users mentioning

I've never been doing such thing but as i can see, the twitter-text-rb gem also helps with extracting mentions. I'm also not sure what you're trying to accomplish and how that exactly should work but knowing that the previously mentioned gem can help you with extracting mentions and knowing how to deal with tags, it should not be a big deal for you to deal with that ;)

Hope that helps

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top