我正在通过 wicket_pdf 生成发票 pdf,这很有效。此 pdf 将在后续流程步骤中用作电子邮件的附件。
# user.rb
def send_last_invoice_email!(invoice)
UserMailer.send_actual_invoice_email(self, invoice).deliver
end
# user_mailer.rb
def send_actual_invoice_email(user, invoice)
@user = user
@invoice = invoice
to = @user.email
# THIS IS THE PROBLEMATIC LINE
attachments["#{@invoice.file_name}"] = File.read(@invoice.file_name_path)
mail(:to => to)
end
# console => works
user = User.where("step_id = 1 AND status = 0").last
invoice = user.invoices.last
user.send_last_invoice_email!(invoice)
# rake task => doesn't work
desc "send email for first user for step_id => 1 testing purpose"
task :send_mail => :environment do
user = User.where("step_id = 1 AND status = 0").last
invoice = user.invoices.last
user.send_last_invoice_email!(invoice)
end
当我调用 RAKE TASK 时,pdf 为空。我已经调试过了,文件名存在,原始pdf文件没问题,但只有电子邮件中附加的pdf是空的。
我在开发模式下使用 letter_opener (1.0.0)。
有谁知道,为什么控制台和通过 rake 任务执行相同的代码有区别?以及如何调试这种差异?