Rails 5 Action Mailer - Prawn PDF错误的参数数量

时间:2016-12-08 07:07:24

标签: ruby-on-rails actionmailer

我已经在我的rails应用程序中设置了prawn来生成:

   format.pdf do
             pdf = SalesByDayPdf.new(@daily_salesnp, @amount_total, @discount_total, @grand_total)
             pdf.render_file "daily_sales.pdf"
             send_data pdf.render, filename: 'daily_sales.pdf', type: 'application/pdf', disposition: 'inline'

        end

这是我的SalesByDayPdf

def initialize(daily_salesnp, grand_total, discount_total, amount_total)
    super()
    @daily_salesnp = daily_salesnp
    @amount_total = amount_total
    @discount_total = discount_total
    @grand_total = grand_total

    header
    text_content
    table_content
    footer
  end

这很好用。

现在我想从动作邮件发送这个pdf。我在DailySalesMailer中将其设置为:

def send_daily_sale(daily_salesnp, grand_total, discount_total, amount_total)
    @daily_salesnp = daily_salesnp
    @amount_total = amount_total
    @discount_total = discount_total
    @grand_total = grand_total

   attachments["daily_sales.pdf"] = SalesByDayPdf.new(daily_salesnp, grand_total, discount_total, amount_total)
   mail(:to => "email@gmail.com", :subject => 'Sales by Day Report')

end

所以基本上我在邮件程序中复制了pdf生成器并传递了我的控制器中定义的相同参数。

但我得到了:

  

错误的参数数量(给定1,预期为4)

我做错了什么?

1 个答案:

答案 0 :(得分:0)

解决方案是将附件修改为:

attachments["daily_sales.pdf"] = SalesByDayPdf.new(daily_salesnp, grand_total, discount_total, amount_total).render