我是新来的轨道。我在向多个模型发送邮件时遇到问题。我们的项目包含家长、教师和学生模型。每个模块都有多个用户(学生、家长、教师)。而且我有三个复选框。即学生,老师,家长。当我点击学生和老师时。邮件应该发送给所有老师和所有学生。
如果我想给老师和学生发送邮件,这背后的问题是,邮件只发送给老师而不是学生。如何解决这个问题。我包括了我的编码。
控制器
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
结尾
用户邮件程序.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
请帮助我。在此先感谢。