Rails PDF Plugin Error Pages

I needed to generate PDFs for the OBRA website, so I installed the Rails PDF plugin and Ruby PDF::Writer.

I’m happy with both. Typical for Ruby and Rails, they “just work” and my code is terse and expressive. (Well, the Rails plugin source code is a bit rough, and there are no unit tests. And the PDF::Writer API is a bit of a head-scratcher, but I blame Adobe for that.)

One minor annoyance is that Rails returns PDF page (.rpdf) errors as “application/pdf” content with names like mypage.pdf.html. Safari, at least, just saves the page to the desktop.

I improved this by overriding a couple methods in my ActionController:

def rescue_action_in_public(exception)
  headers.delete("Content-Disposition")
  super
end

def rescue_action_locally(exception)
  headers.delete("Content-Disposition")
  super
end

And now I get my errors in the browser, where I like them.

Leave a Reply

You must be logged in to post a comment.

gears