The private `new 'method called MyReminderMailer: Class

In the controller, I have:

mailer = MyReminderMailer.new

the mail program is as follows:

class MyReminderMailer < ActionMailer::Base
  def change_email
    mail(
      from:     default_from,
      to:       default_to,
      subject: "..."
    )
  end

  def default_from
    return '...'
  end

  def default_to
    return '...'
  end
end

but got an error: private method `new 'called MyReminderMailer: Class

+3
source share
2 answers

ActionMailer::Basehas a pretty dumb and non-intuitive API. Like controllers, you never explicitly create instances of your email programs. Instead, you interact with them as classes. newmarked private in ActionMailer::Base, and class method calls are then routed through method_missingto a new instance of itself. As I said, unintuitive.

guides api docs ActionMailer.

+12

Ruby .

SomeClass.send :method_name

#in your case
MyReminderMailer.send :new

ActionMailer. .

MyReminderMailer.change_email.deliver

, .

+3

All Articles