-
Notifications
You must be signed in to change notification settings - Fork 21.7k
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
Registering mail interceptor causes warning in Rails 6.1 #42170
Comments
Ultimately the code that's responsible for this is in the
The cause of the warning could be a missing require or something in Action Text - needs investigating before we update the docs. |
@ryanb yep, that guide is wrong - the Configuring Action Mailer section of the configuration guide has the correct format: Rails.application.config.action_mailer.interceptors = ["MyMailInterceptor"] Similarly, observers are: Rails.application.config.action_mailer.observers = ["MyMailObserver"] The reason it's a string and not the class is so that you can save the interceptor/observer in somewhere like The underlying cause of the message you're seeing is that This holds true for other configuration as well - for example setting If for some reason you need to access a base class in an initializer but there isn't a configuration available or it's not configuration related then you can use Active Support ActiveSupport.on_load(:action_mailer) do
ActionMailer::Base.register_interceptor(MyMailInterceptor)
end That warning could probably be more helpful about this situation but it's already quite long - sorry for the confusion. |
@pixeltrix Thank you for taking the time to write such a thorough response. Very informative! |
Thanks @pixeltrix ! |
- Fixes #110 - See: rails/rails#42170 (comment)
- Fixes #110 - See: rails/rails#42170 (comment)
Steps to reproduce
In a new Rails 6.1.3.2 app, create a mail interceptor as documented in the guide.
And then run the test suite.
Expected behavior
No deprecation warning.
Actual behavior
Running the tests shows this warning.
Wrapping the
ActionMailer::Base
call in the recommended block appears to resolve this.However, I have a couple questions.
Will this cause the interceptor to be added multiple times in some cases? I'm uncertain if that call is idempotent.
Should the guide be updated to include this block? Or is there another preferred method for registering an interceptor?
System configuration
Rails version: 6.1.3.2
Ruby version: 2.5.5
The text was updated successfully, but these errors were encountered: