我正在迭代一组订户ID以向每个订阅者发送电子邮件,但由于某种原因,并非所有订阅者都收到该电子邮件。
这是调用模型方法的控制器:
class Admin::EmailDigestsController < ApplicationController
def send_digest
article_ids = params[:article_ids]
subject = params[:subject]
EmailDigest.send_email_digest(article_ids, subject)
redirect_to email_digests_path
end
end
这是email_digest.rb:
class EmailDigest < ActiveRecord::Base
def self.send_email_digest(article_ids, subject)
subscribers = EmailDigest.where.not(status: "Inactive").ids
subscribers.each do |subscriber|
DigestMailer.weekly_digest(subscriber, article_ids, subject).deliver_later
end
end
end
这是digest_mailer.rb:
class DigestMailer < ActionMailer::Base
default from: "secret@secret.com"
def weekly_digest(subscriber, article_ids, subject)
@subscriber = EmailDigest.find_by_id(subscriber)
@subject = subject
articles_arr = []
article_ids.each do |f|
articles_arr << Article.find_by_id(f)
end
@articles = articles_arr
mail(to: @subscriber.email,
subject: subject)
end
end
我也设置了sidekiq并且它足以发送至少一封电子邮件,但也许错误处理方式有问题。
感谢您的帮助