ruby-on-railswkhtmltopdfwicked-pdf

Wicked_pdf cannot find template for pdf


I am trying to render a pdf with wicked pdf in my action.

def show
        respond_to do |format|
            format.html
            format.pdf do
              render pdf: "reciept"
            end
        end
    end

This works fine for html format, but gives me

Missing template /reciept with {:locale=>[:en], :formats=>[:pdf], :variants=>[], :handlers=>[:raw, :erb, :html, :builder, :ruby, :jbuilder]}.

Installed gem 'wicked_pdf' and 'wkhtmltopdf-binary'. Using rails 7. Any help will be appriciated.

I Thought it was issue with gem so reinstalled the gem but nothing changed.


Solution

  • if you moved from rails 6 to rails 7, then you need to remove the .html.erb defined against any attribute (this includes layout).

    rails 6

    render pdf: "receipt", template: 'pdf/receipt.html.erb', layout: "pdf.html.erb", formats: [:html]

    rails 7

    render pdf: "receipt", template: 'pdf/receipt', layout: "pdf", formats: [:html]