I have used wicked pdf gem for html to pdf generate in rails 4.It doesn't work for me and It throw error like this ActionView::MissingTemplate at /events/calendar_month_print.pdf Missing template events/calendar_month_print.html.erb with {:locale=>[:en], :formats=>[:pdf], :variants=>[], :handlers=>[:erb, :builder, :raw, :ruby, :rabl, :rxls, :"xls.rxls", :jbuilder]}. Searched in: and i also created calendar_month_print.html.erb file in my app.I don't know where i'm missing.
My gemfile
gem 'wicked_pdf'
gem 'wkhtmltopdf-binary'
My Controller file
respond_to do |format|
format.html
format.pdf do
render :pdf => "monthly_events.pdf",:template => "events/calendar_month_print.html.erb"
end
end
My view file
<%= button_to "Print as pdf", calendar_month_print_events_path(format: "pdf"), :class => "btn btn-primary button monthly_print pull-right",:method => :get,target: '_blank' %>
My config/initializers/mime_types.rb
Mime::Type.register "application/pdf", :pdf
My config/initializers/wicked_pdf.rb
WickedPdf.config = {
#:wkhtmltopdf => '/usr/local/bin/wkhtmltopdf',
#:layout => "pdf.html",
:exe_path => '/usr/local/bin/wkhtmltopdf'
}
When you give render :pdf => "monthly_events.pdf",:template => "events/calendar_month_print.html.erb"
, Rails expects a file named calendar_month_print.html.erb
in app/views/events
. If you placed it somewhere else, then move it to app/views/events
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With