0

我有这个观察者,它监视评论表,并在创建某些内容后发送电子邮件。我似乎没有在观察者中正确地进行关联,因为我收到错误或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

有没有办法在观察者内部编写正确的关联?

4

1 回答 1

0

所以我发现观察者没有/不应该访问数据库。我现在将我的逻辑移至邮件程序(稍后将移至帮助程序)。然后确保不要使用“消息”作为您的方法名称,因为它是保留的;)

于 2012-11-13T03:18:35.817 回答