Class: Bidi2pdfRails::Railtie

Inherits:
Rails::Railtie
  • Object
show all
Defined in:
lib/bidi2pdf_rails/railtie.rb

Overview

Bidi2pdfRails::Railtie integrates PDF rendering support into a Rails application.

This Railtie is the glue that connects the bidi2pdf rendering engine to the Rails framework. It takes care of:

  • Registering the PDF MIME type (so Rails understands ‘format.pdf`)

  • Adding support for ‘render :pdf` in controllers

  • Hooking into the Rails lifecycle to manage the Chrome headless browser session

  • Applying your custom config for assets, callbacks, and PDF options

With this Railtie loaded, you can use PDF rendering just like any other response format:

def show
  respond_to do |format|
    format.html
    format.pdf do
      render pdf: "invoice", template: "invoices/show"
    end
  end
end

This makes PDF generation feel like a natural part of Rails — even though it’s using headless Chrome and a ton of fancy options under the hood.