Created
May 21, 2013 20:14
-
-
Save redrory/5622855 to your computer and use it in GitHub Desktop.
My client model, when I send the email reminders.
Problem is, I would like to send user information, not sure how to pass in the correct
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
## My daily mail function that sorts through who should be sent email reminders, then passes that | |
##infomation to the mailer function | |
## The client side works [Line 18 ], it finds all appropriate clients and sends to them | |
## However I decided that I want to include information from User. | |
## User has many clients, So the person that signs up is the User, and the clients are sent email reminders. | |
##My issue is that, I wasn't sure how to pass in the correct user instance into the Reminder.daily_mail email function | |
## When I try it how it done now, it sents emails reminders with ALL users. @user = User.current_user doesn't work. | |
## When I try to do a block each user, it send loops and send multiple emails. | |
def self.daily_email | |
@user = User.all | |
@user.each do |u| | |
@user_name = u.name | |
end | |
@client = Client.all | |
@client.each do |c| | |
unless c.email.nil? || if c.reminder == "Daily" && c.paid == false | |
puts "Daily fixed | Company Name " + @user_name + "Client Name | " + c.name | |
Reminder.test_mail.deliver | |
Reminder.daily_email(@user_name,c.id,c.email,c.project_name,c.name,c.amount,c.due_date).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
def daily_email(user_name,id,email,project_name,name,amount,due_date) | |
@user_name = user_name | |
@id = id | |
@name = name | |
@project_name = project_name | |
@amount = amount | |
@due_date = due_date | |
@client = Client.find(id) | |
mail(:to =>email, :subject => "Reminder from "+ @user_name ) | |
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