-
-
Save joseph-ravenwolfe/5623467 to your computer and use it in GitHub Desktop.
This file contains 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
# What we are going to do is retrieve all of the users. | |
# | |
# Then loop through all of the users. For each user that | |
# we loop through, we will get all of their clients. | |
# | |
# Then we will loop through each of that user's clients | |
# and send that client an email. | |
# | |
# We will send the client object into daily_email and | |
# let daily_mail get whatever information it needs | |
# about the client. | |
# | |
def self.daily_email | |
@users = User.all | |
@users.each do |user| | |
clients = user.clients | |
clients.each do |client| | |
if client.email? && client.reminder == "Daily" && !client.paid? | |
puts "Daily fixed | Company Name #{user.username} Client Name | #{client.name}" | |
Reminder.test_mail.deliver | |
Reminder.daily_email(client).deliver | |
end | |
end | |
end | |
end |
This file contains 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
# This requires that a user has_many :clients | |
# and a client belongs_to :user. | |
# | |
def daily_email(client) | |
mail(:to => client.email, :subject => "Reminder from #{client.user.username}" ) | |
puts "Inside Daily email sent method" | |
client.update_attributes(last_email: Time.now, email_sent: true) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment