Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
lighthouse-import opened this issue May 16, 2011 · 1 comment

Comments

@lighthouse-import
Copy link

Imported from Lighthouse. Original ticket at: http://rails.lighthouseapp.com/projects/8994/tickets/6584
Created by andrew.hay.kurtz (at gmail) - 2011-03-15 17:58:10 UTC

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!

@lighthouse-import
Copy link
Author

Imported from Lighthouse.
Comment by ifesdjeen - 2011-03-19 10:44:44 UTC

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant