我在 Rails 4.1 上尝试使用Mailboxer Gem和 Sidekiq,我按照文档和文档中的示例应用程序进行了设置。然后我将邮件程序配置为在以下位置使用 UserMailer initializers/mailboxer.rb
:
config.notification_mailer = UserMailer
config.message_mailer = UserMailer
一切都按预期工作,无论是在网站上还是在发送或回复消息时接收电子邮件。接下来,我尝试使用 Sidekiq 使用我从Mailboxer github 页面上的一个问题中获得的代码来异步完成邮件作业。这也在初始化程序中:
config.custom_deliver_proc = ->(mailer, mailable, recipient) do
mailer.delay.send_email(mailable, recipient)
end
但是,现在当我发送消息时,它会命中 Sidekiq,但会引发此错误:
ArgumentError: undefined class/module Mailboxer::Message
这是 user_mailer.rb 中的相关代码:
def send_email(message, receiver)
if message.conversation.messages.size > 1
reply_message_email(message,receiver)
else
new_message_email(message,receiver)
end
end
#Sends an email for indicating a new message for the receiver
def new_message_email(message,receiver)
@message = message
@receiver = receiver
set_subject(message)
mail :to => receiver.send(Mailboxer.email_method, message),
:subject => t('mailboxer.message_mailer.subject_new', :subject => @subject),
:template_name => 'new_message_email'
end
#Sends and email for indicating a reply in an already created conversation
def reply_message_email(message,receiver)
@message = message
@receiver = receiver
set_subject(message)
mail :to => receiver.send(Mailboxer.email_method, message),
:subject => t('mailboxer.message_mailer.subject_reply', :subject => @subject),
:template_name => 'reply_message_email'
end
我目前没有使用通知,所以我没有包括在内。它在哪里调用 Mailboxer::Message,它期望什么参数?这是 Rails 4.1 的事情吗?我对 Ruby/Rails 还是很陌生,如果这对我来说是一个明显的错误,我很抱歉。
我还尝试调用delay
UserMailer 中的各个方法,结果相同:
def send_email(message, receiver)
if message.conversation.messages.size > 1
UserMailer.delay.reply_message_email(message,receiver)
else
UserMailer.delay.new_message_email(message,receiver)
end
end