当前位置: 动力学知识库 > 问答 > 编程问答 >

ruby on rails - Prawn PDF and Action Mailer not attaching PDF

问题描述:

I'm using Prawn PDF and Actionmailer to send a pdf on completion of a sign up form, but it's just sending text rather then attaching the pdf. Not quite sure what i'm missing, but any help would be appriciated.

Example

--

Content-Type: application/pdf;

charset=UTF-8

Content-Transfer-Encoding: base64

Content-Disposition: attachment;

filename=file.pdf

JVBERi0xLjQKJf////8KMSAwIG9iago8PCAvQ3JlYXRvciA8ZmVmZjAwNTAw

MDcyMDA2MTAwNzcwMDZlPgovUHJvZHVjZXIgPGZlZmYwMDUwMDA3MjAwNjEw...

PRAWN PDF

# encoding: utf-8

class FormPdf < Prawn::Document

def initialize(form)

super()

@form = form

all

end

def all

text "Form text here"

end

end

Controller

def create

@form = Form(params[:form])

respond_to do |format|

if @form.save

FormMailer.send_form(@form).deliver

else

end

end

end

Mailer

class FormMailer < ActionMailer::Base

default from: "[email protected]"

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

网友答案:

I have resolved this. Realised i didn't have a view template.

分享给朋友:
您可能感兴趣的文章:
随机阅读: