Umar Bhai
Umar Bhai

Reputation: 48

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.

Upvotes: 0

Views: 418

Answers (2)

luke
luke

Reputation: 1578

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]

Upvotes: 1

Umar Bhai
Umar Bhai

Reputation: 48

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

Must tell formats to html if using recipt.html.erb or else it will give missing template error in rails 7. For using .pfd.erb file, without formats work.

Upvotes: 1

Related Questions