Comments (7)
Valid.
from rails.
Here's some code to do this: just add to config/initializers/action_mailer_enhanced_hooks.rb
:
module ActionMailerEnhancedHooks
def self.included(base)
base.extend(ClassMethods)
end
module ClassMethods
def after_deliver(method_name, options = {})
new_method_name = generate_method_name(method_name, options)
condition = if options[:only]
"Array(#{options[:only].inspect}).include?(action_name.to_sym)"
elsif options[:except]
"!Array(#{options[:except].inspect}).include?(action_name.to_sym)"
else
"true"
end
class_eval <<-RUBY, __FILE__, __LINE__ + 1
def #{new_method_name}(*args)
return unless #{condition}
#{method_name}(*args)
end
RUBY
super(new_method_name)
end
private
def generate_method_name(method_name, options)
suffix = if options[:only]
"_only_#{Array(options[:only]).join('_')}"
elsif options[:except]
"_except_#{Array(options[:except]).join('_')}"
else
""
end
"#{method_name}#{suffix}".to_sym
end
end
end
ActionMailer::Base.include ActionMailerEnhancedHooks
Now you can use only and except in your hooks.
from rails.
Delivery callbacks were added in #47630 (cc @bensheldon).
The feature request looks legitimate for me and I am willing to help by creating a PR. But, was there a reason to not add these options back then?
from rails.
Those callback options being absent was unintentional. I think that makes sense for the _delivery
callbacks to be consistent with _action
callbacks.
Also, revisiting my implementation in light of this, I wonder if there is a better implementation for _delivery
callbacks rather than including ActiveSupport::Callbacks
and maybe they should have been created with something in AbstractController
instead
from rails.
This issue has been automatically marked as stale because it has not been commented on for at least three months.
The resources of the Rails team are limited, and so we are asking for your help.
If you can still reproduce this error on the 7-1-stable
branch or on main
, please reply with all of the information you have about it in order to keep the issue open.
Thank you for all your contributions.
from rails.
Haven't tested but it would be great to have this feature OR document that only / except callbacks don't work.
from rails.
hacky way to currently do this currently is to do return unless action_name == :the_method_name
in the callback method.
from rails.
Related Issues (20)
- [Bug][Railties] Generating scaffold don't apply tailwindcss template if rails new command with '--css=tailwind --javascript=esbuild' HOT 2
- postgresql hstore column not working with schema dump and rspec HOT 3
- Can't use ActiveRecord::Base.connection to check the existence of the DB in Rails 7.2.1 HOT 2
- ActionText adding a spurious `content: ''` to rich text attachments causing them to not preview in the editor HOT 1
- Time.find_zone has inconsistent behavior between mac and linux environments for "America/Indianapolis" HOT 3
- Make it possible for ConnectionPool#disconnect to avoid reconnection HOT 1
- Syntax error on first db:migrate after upgrading to rails 6 HOT 4
- Multiple rate-limits share same cache key so it increments multiple time for single request
- UniquenessValidator raises error when used on singleton class HOT 13
- Errors reported when ActionMailer emails are sent via ActiveJob do not filter mailer params, potentially leak sensitive data HOT 9
- Mapping column manually like type/class to c_type/c_class HOT 4
- "Cannot expire connection, it is owned by a different thread" in Rails 7.2 tests HOT 4
- Rails console reload! command HOT 3
- Precision and scale not detected for custom DOMAIN types [PostgreSQL]
- Fresh Rails project contains rubocop linter violation
- ActionCable stream_from handlers not called in test
- Bug in generated Dockerfile when using ruby preview versions HOT 2
- Remove deprecated code
- HashWithIndifferentAccess#deep_stringify_keys vs non-string keys HOT 1
- # Contributor Code of Conduct The Rails team is committed to fostering a welcoming community. **Our Code of Conduct can be found here**: https://rubyonrails.org/conduct For a history of updates, see the page history here: https://github.com/rails/website/commits/main/_pages/conduct.html
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rails.