ActionMailer - 提前返回另一个邮件程序

时间:2014-05-27 10:25:45

标签: ruby-on-rails ruby return actionmailer mailer

如果满足某些条件,我需要从ActionMailer方法提前返回并使用其他操作发送其他电子邮件。

class IssueNotificationMailer < Mailer
  include Rails.application.routes.url_helpers

  def send_notification(id)
    notification = Notification.find_by_id(id)
    return unless notification
    user, @issue = notification.user, notification.issue
    return unless user && user.active?
    return (render :nothing => true and deleted_issue(notification)) if @issue.nil?
    @url = issue_url(@issue)
    mail(to: user.mail, subject: "Issue #{@issue.subject} requires your attention.")
  end

  def deleted_issue(notification)
    user = notification.user
    @url = user_notifications_url(user)
    mail(to: user.mail, subject: "Issue which required your attention was deleted.")
  end
end

我想阻止发送send_notification电子邮件:

return (render :nothing => true and deleted_issue(notification)) if @issue.nil?

但它仍然希望发送第一封提出的电子邮件

ActionView::Template::Error: undefined method `subject' for nil:NilClass

有什么想法吗?

0 个答案:

没有答案