Created
November 13, 2011 12:00
-
-
Save qoobaa/1362033 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class UserMailer < ActionMailer::Base | |
# ... | |
def daily_news(user) | |
mail(to: user.email, subject: "Daily newsletter") | |
end | |
private | |
def accepts_delivery?(address) | |
user = User.find_by_email(address) | |
user.present? and user.send("wants_#{action_name}_email?") | |
end | |
def mail(headers = {}, &block) | |
super(headers, &block) | |
message.perform_deliveries = message.to.all? do |address| | |
accepts_delivery?(address) | |
end | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class User < ActiveRecord::Base | |
# ... | |
def wants_daily_news_email? | |
email_confirmed? and # ... | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# deliver conditionally | |
UserMailer.daily_news(user).deliver | |
# force delivery | |
UserMailer.daily_news(user).deliver! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment