This project is archived and is in readonly mode.

#6584 new
andrew.hay.kurtz (at gmail)

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

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

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!

Comments and changes to this ticket

  • ifesdjeen

    ifesdjeen March 19th, 2011 @ 10:44 AM

    • 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.

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

People watching this ticket

Pages