【发布时间】:2014-08-15 07:03:11
【问题描述】:
我的评论模型上有一个回调,它创建一个通知,该通知将发送给适当的成员,但如果 current_member 正在评论他自己的可评论对象,我不希望它创建通知。我试过像这样使用除非条件:
after_create :create_notification, on: :create, unless: Proc.new { |commentable| commentable.member == current_member }
def create_notification
subject = "#{member.user_name}"
body = "wrote you a <b>Comment</b> <p><i>#{content}</i></p>"
commentable.member.notify(subject, body, self)
end
但我收到此错误:undefined local variable or method 'current_member' for #<Comment:0x746e008
如何让它按我想要的方式工作?
【问题讨论】:
标签: ruby-on-rails model callback conditional