Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

ActionMailer::Base has an undocumented public attribute, leading to confusion

#6584

I'm on rails 3.0.5. ActionMailer::Base has an internal attribute created with the name 'message', and this fact is not documented. If you happen to try to define a delivery method called 'message' on one of your mailers, fun things happen. It is documented that there is a message object available to a mailer view. However, I do not think of the view and controller as being the exact same context (though they share instance vars), so it did not occur to me that I am not allowed to 'def message' inside a mailer.

Steps to reproduce:
1. create a new mailer
2. define two delivery methods, call one of them 'message'. Make it accept an argument or three for extra confusion.
3. Try to send an email with the method that isn't called 'message'.
4. Read the exception.

Gist of my mailer:
https://gist.github.com/871136

Gist of exception from my rspec test:
https://gist.github.com/871143

Thanks a lot!

Reported by andrew.hay.kurtz (at gmail) · March 15th, 2011 @ 05:58 PM

State: new
Milestone: none
Assigned to: nobody
Importance: none

Activity

  1. ifesdjeen
    ifesdjeen
    • Tag set to actionmailer

    It's not a direct part of ActionMailer::Base. It's more a part of MailHelper (actionmailer/lib/action_mailer/mail_helper.rb).

    It's an accessor to @_message instance variable.

    Naming things is one of the biggest problems, actually :) If you say it's a delivery method, you should probably call it "deliver_message" and the other one would become "deliver reply".

    So, having message method is completely legitimate in that particular case. If you want to change a message accessor itself, feel free to override it.

    March 19th, 2011 @ 10:44 AM