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タスクを介して同じコードを実行することに違いがあるのはなぜですか? そして、どうすればこの違いをデバッグできますか?