邮件不在ROR中

时间:2016-12-06 06:01:03

标签: ruby-on-rails

我正在尝试发送邮件但是该值不会发送。请帮助我如何发送价值。 控制器部分 -

@c1=IssueTrackerGroup.where(id:@issue_request.issue_tracker_group_id).pluck(:id)

@c2 = IssueTrackerMember.where(issue_tracker_group_id: @c1).pluck(:employee_id)

        @emp = Employee.where(id: @c2)
        @emp.each do |s|
        IssueRequestMailer.issue_tracker_group_email(s.email).deliver_now
        end

邮件部分 -

def issue_tracker_group_email(s)
 s=s
 mail(to: s, subject: 'Support Request') 
 end

我要传递的参数 -

<!DOCTYPE html>
<html>
  <head>
    <meta content='text/html; charset=UTF-8' http-equiv='Content-Type' />
  </head>
  <body>

 <h4>Support Request</h4>
    <p>
      This is to inform you that you have a support Request .
      Details are given below.<br><br>

<b>1. Support Master</b> - <%= @issue_request.try(:issue_master).try(:name) %><br><br>

      <b>2. Support Group</b> - <%= @issue_request.try(:issue_tracker_group).try(:name) %><br><br>

      <b>3. Support Priority</b> - <%= @issue_request.try(:issue_priority) %><br><br>

      <b>4. Description</b> - <%= @issue_request.try(:description) %><br><br>
        With Regards,<br><br>
        HR
     </p>
  </body>
</html>  

1 个答案:

答案 0 :(得分:1)

将变量@issue_request@c1@c2传递给issue_tracker_group_email方法。

IssueRequestMailer.issue_tracker_group_email(s.email, @issue_request, @c1, @c2).deliver_now

然后在issue_tracker_group_email方法中声明实例变量以将数据共享到视图。 (我在视图中假设您需要的实例变量。)

def issue_tracker_group_email(mail_id, request, c1, c2)
  @issue_request = request
  @c1 = c1
  @c2 = c2
  mail(to: mail_id, subject: 'Support Request') 
end

现在,您可以在视图中使用@issue_request@c1@c2

P.S。使用有意义的变量名称。

希望这有帮助!