Set request.format and response headers
Figured it out. According to Rails source , request.format = 'pdf' will manually set the response format in PDF format. This means that Rails will display, for example, show.pdf.haml .
However, now PDFKit will not convert the response to an actual PDF, because the Content-Type header says that it is already a PDF, when we actually only generate HTML. Therefore, we also need to override the Rails response header to say that it is still HTML.
This controller method processes it:
This means that the action of the controller is as follows:
def show @invoice = Finance::Invoice.get!(params[:id])
source share