我通过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任务执行相同代码之间存在差异?我怎么能调试这个差异?
答案 0 :(得分:0)
# users.rake
namespace :users do
Encoding.default_external = Encoding::UTF_8
Encoding.default_internal = Encoding::UTF_8
...
我希望也许其他人可以从我2天的努力中获利:-)。 欢呼声