Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 如何将邮件发送到rails中的一堆邮件id_Ruby On Rails_Email - Fatal编程技术网

Ruby on rails 如何将邮件发送到rails中的一堆邮件id

Ruby on rails 如何将邮件发送到rails中的一堆邮件id,ruby-on-rails,email,Ruby On Rails,Email,嗨,我一直在开发一个简单的学校项目,如果学生注册完成,我想把邮件发送到startmark条目 我有桌子 配给 *section_id *user_id 使用者 登记管理员 def update unless params[:students] && params[:section_id] && !params[:is_academic].nil? send_back GlobalUtils.false_response_hash and return end

嗨,我一直在开发一个简单的学校项目,如果学生注册完成,我想把邮件发送到startmark条目

我有桌子

配给

*section_id
*user_id
使用者

登记管理员

def update
unless params[:students] && params[:section_id] && !params[:is_academic].nil?
  send_back GlobalUtils.false_response_hash and return
end

section = Section.find( params[:section_id] )
Mailers.mark_entry_notification(section).deliver
send_back( response_hash, :scope_3 )
end


mailers.rb

def mark_entry_notification(section)  
section_id = section.id
array_user_id=[]
Allotment.each do |allot|
  array_user_id << allot.user_id.where(allot.section_id = section_id)
end
array_user_mail=[]
User.each do |usr|
  array_user_mail << usr.user_email.where(usr.user_id = array_user_id)
end
mail(:to => "array_user_mail" :subject => student enrollment is completed  )
end
def更新
除非参数[:学生]&¶ms[:section_id]&&!params[:是学术性的].nil?
返回GlobalUtils.false\u响应\u散列并返回
结束
section=section.find(参数[:section\u id])
邮递员。标记输入通知(部分)。递送
发回(响应\u散列,:作用域\u 3)
结束
mailers.rb
def标记进入通知(第节)
section_id=section.id
数组\用户\ id=[]
分配|
数组\u用户\u id学生注册已完成)
结束
这是正确的吗?这将发送邮件吗?

邮件(:to=>数组\用户\邮件:主题=>学生注册已完成)

记下粗体字。ruby变量不需要使用引号。您可以通过这种方式向多个用户发送邮件

我想知道为什么您编写这么多行代码只是为了获取用户模型的电子邮件ID

array_user_mail = User.pluck(:user_email)
如果您使用的是较低版本的rails,请尝试以下操作

array_user_mail = User.map(&:user_email)
另外,您确定以下代码在您的应用程序中有效吗

 array_user_id << allot.user_id.where(allot.section_id = section_id)

array\u user\u id我希望这就是您所期望的:

在注册管理员中

def update
    unless params[:students] && params[:section_id] && !params[:is_academic].nil?
      send_back GlobalUtils.false_response_hash and return
    end

    Mailers.mark_entry_notification(params[:section_id]).deliver
    send_back( response_hash, :scope_3 )
end
在mailers.rb中

def mark_entry_notification(section_id)  
    array_user_ids = array_user_emails = [] 
    array_user_ids = Allotment.where(:section_id=>section_id).pluck(:user_id)   
    array_user_emails = User.where(:id=>array_user_ids).pluck(:user_email)
    mail(:to => array_user_emails, :subject => "Student enrollment is completed" )
end
希望这对你有帮助


谢谢

在此过程中使用延迟作业,您可以使用第三方电子邮件服务,如使用延迟作业的MailgunIam。编码中有错误吗?我想知道数组\u user\u mail mailer.rb中的代码是否完全不起作用。我不懂密码。您希望如何收集用户以发送邮件。让我试着帮助你。我使用它是因为我不需要整个模型的电子邮件id,只需要用户id匹配到的用户的用户邮件来找到用户的id
def mark_entry_notification(section_id)  
    array_user_ids = array_user_emails = [] 
    array_user_ids = Allotment.where(:section_id=>section_id).pluck(:user_id)   
    array_user_emails = User.where(:id=>array_user_ids).pluck(:user_email)
    mail(:to => array_user_emails, :subject => "Student enrollment is completed" )
end