您可以在模型中添加一个模块
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
。如果您需要,这可能会更复杂......如果 Cylon 尝试启动消息或 Duck 尝试回复,可能会引发异常。