I can create a PDF document using PRAWN, but when I try to download as
an attachment via a link, nothing appears to happen. When I go into the
/tmp/pdfs/ directory of my rails app, I can see the created PDF
document.
Can anyone see why the pdf doc will not download?
Thanks,
Frank
VIEW
Download to PDF
<%= link_to_remote image_tag("/images/icons/download_to_pdf.jpg"), :url
=> {:controller => “reports”, :action => “make_pdf”} %>
CONTROLLER
def make_pdf
filename = ‘prawn.pdf’
pdf = Prawn::Document.new
pdf.text("Prawn Rocks")
pdf.render_file('tmp/pdfs/prawn.pdf')
send_file "#{RAILS_ROOT}/tmp/pdfs/#{filename}", :type =>
‘application/pdf’, :disposition => ‘attachment’
end
2010/1/5 Frank K. [email protected]:
filename = 'prawn.pdf'
pdf = Prawn::Document.new
pdf.text("Prawn Rocks")
pdf.render_file('tmp/pdfs/prawn.pdf')
send_file "#{RAILS_ROOT}/tmp/pdfs/#{filename}", :type =>
‘application/pdf’, :disposition => ‘attachment’
end
Have you checked the html of the page to see if the link looks correct
(View, Page Source or similar in your browser). If it does look ok
does it work if you type it into browser directly?
Colin
–
You received this message because you are subscribed to the Google
Groups “Ruby on Rails: Talk” group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
That worked Fred. Thank you both for your help.
Frederick C. wrote:
On Jan 5, 2:29�pm, Frank K. [email protected] wrote:
I can create a PDF document using PRAWN, but when I try to download as
an attachment via a link, nothing appears to happen. �When I go into the
/tmp/pdfs/ directory of my rails app, I can see the created PDF
document.
Because you’ve got a link_to_remote - that just creates a Ajax.Request
object that fetches the data and then ignores it - use a regular link.
Fred
On Jan 5, 2:29 pm, Frank K. [email protected] wrote:
I can create a PDF document using PRAWN, but when I try to download as
an attachment via a link, nothing appears to happen. When I go into the
/tmp/pdfs/ directory of my rails app, I can see the created PDF
document.
Because you’ve got a link_to_remote - that just creates a Ajax.Request
object that fetches the data and then ignores it - use a regular link.
Fred
<%= link_to_remote image_tag(“/images/icons/download_to_pdf.jpg”), :url
pdf.render_file(‘tmp/pdfs/prawn.pdf’)
send_file "#{RAILS_ROOT}/tmp/pdfs/#{filename}", :type =>
‘application/pdf’, :disposition => ‘attachment’
end
–
Posted viahttp://www.ruby-forum.com/.
–
You received this message because you are subscribed to the Google
Groups “Ruby on Rails: Talk” group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.