【发布时间】:2014-02-21 03:59:41
【问题描述】:
使用 rails4,我正在尝试实现通知模型。在这里,我使用 ActiveSupport::Concern 将我的通知相关代码与模型分开。 create_notification_module.rb
module CreateNotificationModule
extend ActiveSupport::Concern
include ActiveModel::Dirty
included do
after_update :notify
after_create :notify
after_create :notify
end
def notify
record = Notification.new(
:ref_table => self.class,
:ref_id => self.id,
:receiver => ? , # owner of the parent model if parent exists
:sender => current_user.id,
:details => self.changes,
:is_read => 0)
record.save!
end
这里我需要知道这个回调是从哪个控制器/模型调用的,这样我就可以编写我的 switch case。例如, 案例评论:获取用户cmet的消息的所有者 案例如:获取喜欢的 msg/cmt 的所有者等,不胜感激。
【问题讨论】:
标签: ruby-on-rails-4 callback activesupport-concern