Mailboxer允许您连接多个模型,如从gem页面中的示例中所示。邮递员吉特布页面
您可以在任何其他模型中使用Mailboxer,并在几种不同的模型中使用它。如果您的应用程序中有鸭子和cylons,并且您想要像它们一样交换消息,只需在每个应用程序中添加acts_as_messageable,您就可以发送鸭-鸭、鸭-赛隆、赛昂-鸭子和赛隆-赛隆消息。
我们如何将消息限制在鸭-赛隆之间,反之亦然?所以,只有鸭子才能开始对话,赛昂人才能回答?而且,鸭子和赛昂人之间的对话是不可能的?
发布于 2014-06-30 08:40:18
您可以向模型中添加一个模块。
class Duck < ActiveRecord::Base
acts_as_messageable
include mailboxer_filter
end和
class Cylon < ActiveRecord::Base
acts_as_messageable
include mailboxer_filter
end你的舱..。
module MalboxerFilter
def initiator?
self.class == Duck
end
def replyer?
self.class == Cylon
end
def send_message_filtered(beta, body, subject)
self.send_message(beta, body, subject) if initiator? && beta.replyer?
end
def reply_to_sender_filtered(*args)
self.reply_to_sender(*args) if replyer?
end
end然后在应用程序中使用send_message_filtered和reply_to_sender_filtered。如果你需要的话这会更复杂..。如果赛昂人试图发起一条消息,或者一只鸭子试图回复,也许会引发一个例外。
https://stackoverflow.com/questions/24485448
复制相似问题