How do i download prawn pdf file while using form submit? [closed]
def index
@forms = Form.all
respond_to do |format|
format.html
end
end
def submit
respond_to do |format|
format.pdf {render }
end
开发者_Python百科 end
submit.pdf.prawn file
pdf.text "successfully submitted"
It is possible for Prawn to generate and return the PDF without having to to save locally...
def submit
send_data(generate_pdf, :filename => "output.pdf", :type => "application/pdf")
end
private
def generate_pdf
Prawn::Document.new do
text "Hello Stackoverflow"
end.render
end
Use prawn to generate a pdf that's saved somewhere in your /public folder, like:
Prawn::Document.generate("#{RAILS_ROOT}/public/pdfs/myfile.pdf")
Then just use your controller to redirect users to that location:
redirect_to '/pdfs/myfile.pdf'
精彩评论