class NotificationsMailer < ApplicationMailer
# https://guides.rubyonrails.org/action_mailer_basics.html#action-mailer-callbacks
after_action :prevent_delivery
def unread
@user = params[:user]
mail(to: @user.email, subject: 'Here's what you missed...')
end
private
def prevent_delivery
mail.perform_deliveries = @user.should_perform_delivery?
end
end
class User < ApplicationRecord
...
def should_perform_delivery?
# @user.should_perform_delivery?
# => false
end
end