我知道这个问题已经过时了,但我最近发布了一个MentionSystem gem到rubygems.org,它允许在提及者对象和提及者之间创建提及,它还允许您检测facebook/twitter styler中的提及,例如@ username1和#hashtag为了创建提及。
宝石托管在GitHub上:https://github.com/pmviva/mention_system
比方说你有一个帖子,可以提及用户@username的形式。
你有类
class Post < ActiveRecord::Base
act_as_mentioner
end
和
class User < ActiveRecord::Base
act_as_mentionee
end
然后定义一个定制的提处理器:
class PostMentionProcessor < MentionSystem::MentionProcessor
def extract_mentioner_content(post)
return post.content
end
def find_mentionees_by_handles(*handles)
User.where(username: handles)
end
end
然后在您的帖子控制器创建操作你必须:
def create
@post = Post.new(params[:post])
if @post.save
m = PostMentionProcessor.new
m.add_after_callback Proc.new { |post, user| UserMailer.notify_mention(post, user) }
m.process_mentions(post)
end
respond_with @post
end
如果您的文章在其内容中包含@ user1,@ user2和@ user3,提及处理器将解析user1,user2和user3,将找到具有用户名[user1,user2,user3]的用户,然后在数据库中创建提及,在每一次提及之后,它将运行后面的回调,在该示例中将发送通知邮件和用户之间的提及的电子邮件。
我鼓励你在这个问题上添加“facebook”和“twitter”标签,这样其他人可能会更容易碰到它。此外,也许开始对此的赏金?我相信很多人都对这个问题的答案感兴趣。 – dmonopoly
@daze:谢谢你的建议。添加正确的标签确实有帮助。 :) –