Skip to content

Instantly share code, notes, and snippets.

@joseph-ravenwolfe
Forked from redrory/client.rb
Last active December 17, 2015 14:19
Show Gist options
  • Save joseph-ravenwolfe/5623467 to your computer and use it in GitHub Desktop.
Save joseph-ravenwolfe/5623467 to your computer and use it in GitHub Desktop.
# 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 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