Wicked_PDF templates is missing
Asked Answered
D

2

19

I installed wicked PDF and modified my controller :

def show
  respond_to do |format|
    format.pdf do
      render :pdf => "file_name"
    end
    format.html
  end
end

Here is how i link to the pdf : compte_contrat_path(c,:format=>'pdf')

It works for html (without the format) but fail for PDF with the following error :

Template is missing

Missing template contrats/show with {:locale=>[:fr], :formats=>[:pdf], :handlers=>[:erb, :builder, :coffee, :arb]}. Searched in: * "/home/sylario/ruby/place_de_marche/app/views" * "/usr/local/rvm/gems/ruby-1.9.2-p136/gems/activeadmin-0.5.0/app/views" * "/usr/local/rvm/gems/ruby-1.9.2-p136/gems/kaminari-0.14.1/app/views" * "/usr/local/rvm/gems/ruby-1.9.2-p136/gems/devise-2.2.0/app/views"

What am I doing wrong?

Dela answered 9/7, 2013 at 13:28 Comment(2)
do you have the template called show.pdf.erb?Raster
the exemple i used was in haml, that may be thatDela
D
37

Thanks to henry I now know it was related to the format of the ERB. I have found a way to reuse my html.erb files :

First i do the following in the controller

format.pdf do
    render  :pdf => "file.pdf", :template => 'contrats/show.html.erb'
end

Then when i use partials i call them like this :

render :partial => 'fullpath/toview.html.erb', :formats => [:html], :locals => { :mylocal=>@something }
Dela answered 9/7, 2013 at 15:48 Comment(2)
My problem was I wasn't using full 'show.html.erb', instead I used only 'show'Spiel
The wicked_pdf readme file should include this as it is a required convention override. Thanks!Sheerness
F
12

For Rails 7, this is what works:

format.pdf do
  render pdf: "file_name", template: "posts/show", formats: [:html]
end

Notice that template no longer have .html.erb and don't forget to include 'formats'.

Faille answered 11/8, 2022 at 19:50 Comment(1)
Worked for me using Rails 7, just needed the "formats: [:html]"Archaeo

© 2022 - 2024 — McMap. All rights reserved.