0
我正在通過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任務執行相同的代碼有區別?我怎麼能調試這種差異?