Let’s say your users are trying to access some pdf files that you’re serving inline with wicked_pdf or any other gem of you choice that is a wrapper for
wkhtmltopdf. But they have to sign in first.
What happens when you use devise and you hit pdf url as unauthorized user? By default your app will respond with
401 Unauthorized which will get converted into invalid pdf file and this kinda not what you want. Probably ;).
This can be fairly easy resolved with the help of custom failure_app. Let the code speak for itself:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
And that’s the simple remedy for our pain ;–).
You can also try playing with
Devise.navigational_formats, unfortunately I regret that I didn’t wrote that blog-post few weeks ago, because I recall that I stumbled upon some issue while trying to solve it that way. I ended up with custom failure app after all, but right now I simply don’t remember exact reasoning :P.