我有这个观察者,它监视评论表,并在创建某些内容后发送电子邮件。我似乎没有在观察者中正确地进行关联,因为我收到错误或ArgumentError (wrong number of arguments (0 for 5)):
使用此代码:
class CommentObserver < ActiveRecord::Observer
def after_create(comment)
if comment.guest_comment == true
if comment.name?
InvoiceMailer.message(comment.name, comment.content, comment.email, comment.user.email, comment.order_id).deliver
elsif comment.email?
# do something if there's no email yet
InvoiceMailer.message(comment.name, comment.content, comment.order.customer.email, comment.user.email, comment.order_id).deliver
else
InvoiceMailer.message(comment.email, comment.content, comment.email, comment.user.email, comment.order_id).deliver
end
else
# owner made the comment
if comment.user.account.company_name?
InvoiceMailer.message(comment.user.name+", "+comment.user.account.company_name, comment.content, comment.user.email, comment.email, comment.order_id).deliver
else
InvoiceMailer.message(comment.user.name, comment.content, comment.user.email, comment.email, comment.order_id).deliver
end
end
end
end
有没有办法在观察者内部编写正确的关联?