Before the filter in action, the Rails 3 email program

What I need:

Something similar to before_filter in ActionMailer in Rails 3.

Problem:

I am working on Rails 3 and want to have before_filter in ActionMailer. I checked the actionmailer api and found out about the before_action and after_action callbacks. When implemented, it gives an error:

NoMethodError: undefined method `before_action' for Notifier:Class 

It later became clear that before calling the Rails 3 command, there is no this message

Is there any hook or gem so we have something similar to before_filter in Rails 3.

Please, help. Many thanks!

+7
callback ruby-on-rails-3 actionmailer
source share
1 answer

This can be achieved by including AbstractController :: Callbacks. This mimics the Rails 4 change, which, in addition to comments and tests, simply included callbacks.

 class MyMailer < ActionMailer::Base include AbstractController::Callbacks after_filter :check_email def some_mail_action(user) @user = user ... end private def check_email if @user.email.nil? message.perform_deliveries = false end true end end 

Link - How to add before_filter to UserMailer, which checks if sending mail to the user is normal?

+10
source share

All Articles