How to send mail for multiple models in rails
I am new to rails. I am having problem in mail sending to multiple models.
Our project contains parent,teacher and student models.each module having
number of users(student,parent,teacher). And also I am having three check
box.that is student,teacher,parent.when I click student and teacher.the
mail should be sent to all teachers and all students.
If I want send a mail to teacher and also student means ,the problem
behind this, mail was sending only to teacher not student. how to solve
this problem.and I included my coding.
Controller
def send_news_letter
if params[:announcement].present?
@announcement = Announcement.find(params[:announcement].keys).first
end
if params[:students].present? and params[:teachers].present?
@student = Student.pluck(:email)
@teacher = Teacher.pluck(:email)
UserMailer.send_multiple_email(@student,@teacher,@announcement).deliver
redirect_to announcements_url, :notice => "Newsletter Delivered
Successfully" a
end
end
Usermailer.rb
class UserMailer < ActionMailer::Base
default to: Proc.new {Teacher.pluck(:email)},
to: Proc.new {Student.pluck(:email)},
from: "from@example.com"
# Subject can be set in your I18n file at config/locales/en.yml
# with the following lookup:
#
# en.user_mailer.password_reset.subject
#
def password_reset(user)
@user = user
mail :to => user.email, :subject => "Password Reset"
end
def send_multiple_email(user,employee,announcement)
@user = user
@employee = employee
@announcement = announcement
mail :subject => "Deliver"
end
end
Please help me.Thanks in advance.
No comments:
Post a Comment