大虾PDF和Action Mailer不附PDF
Prawn PDF and Action Mailer not attaching PDF
我正在使用 Prawn PDF 和 Actionmailer 在完成注册表单后发送 pdf,但它只是发送文本而不是附加 pdf。不太确定我遗漏了什么,但我们会提供任何帮助。
例子
--
Content-Type: application/pdf;
charset=UTF-8
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename=file.pdf
JVBERi0xLjQKJf////8KMSAwIG9iago8PCAvQ3JlYXRvciA8ZmVmZjAwNTAw
MDcyMDA2MTAwNzcwMDZlPgovUHJvZHVjZXIgPGZlZmYwMDUwMDA3MjAwNjEw...
大虾PDF
# encoding: utf-8
class FormPdf < Prawn::Document
def initialize(form)
super()
@form = form
all
end
def all
text "Form text here"
end
end
控制器
def create
@form = Form(params[:form])
respond_to do |format|
if @form.save
FormMailer.send_form(@form).deliver
else
end
end
end
邮寄者
class FormMailer < ActionMailer::Base
default from: "noreply@random.com"
def send_form(form)
@g form = form
pdf = FormPdf.new(@ form)
attachments["file.pdf"] = { mime_type: 'application/pdf', content: pdf.render() }
mail to: @form.email, subject: "Form"
end
end
我已经解决了这个问题。意识到我没有视图模板。
我正在使用 Prawn PDF 和 Actionmailer 在完成注册表单后发送 pdf,但它只是发送文本而不是附加 pdf。不太确定我遗漏了什么,但我们会提供任何帮助。
例子
--
Content-Type: application/pdf;
charset=UTF-8
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename=file.pdf
JVBERi0xLjQKJf////8KMSAwIG9iago8PCAvQ3JlYXRvciA8ZmVmZjAwNTAw
MDcyMDA2MTAwNzcwMDZlPgovUHJvZHVjZXIgPGZlZmYwMDUwMDA3MjAwNjEw...
大虾PDF
# encoding: utf-8
class FormPdf < Prawn::Document
def initialize(form)
super()
@form = form
all
end
def all
text "Form text here"
end
end
控制器
def create
@form = Form(params[:form])
respond_to do |format|
if @form.save
FormMailer.send_form(@form).deliver
else
end
end
end
邮寄者
class FormMailer < ActionMailer::Base
default from: "noreply@random.com"
def send_form(form)
@g form = form
pdf = FormPdf.new(@ form)
attachments["file.pdf"] = { mime_type: 'application/pdf', content: pdf.render() }
mail to: @form.email, subject: "Form"
end
end
我已经解决了这个问题。意识到我没有视图模板。