private method `new' called for MyReminderMailer:Class

actionmailer, ruby

Solution

`ActionMailer::Base` has a rather goofy and unintuitive API. Much like controllers, you never explicitly create instances of your mailers. Instead, you interact with them as classes. `new` is marked private in `ActionMailer::Base`, and method calls on the class are subsequently routed through `method_missing` to a new instance of itself. Like I said, unintuitive.

Have a look at the guides and api docs for more information on the correct usage of ActionMailer.

Problem

In a controller, i have: ``` mailer = MyReminderMailer.new ``` the mailer looks like this: ``` 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 error: private method `new' called for MyReminderMailer:Class

Original source