我已经使用wicked pdf gem for html to pdf generate in rails 4.它对我不起作用,它会在/events/calendar_month_print.pdf中抛出这样的 ActionView :: MissingTemplate 缺少模板事件/ calendar_month_print.html.erb,其中包含{:locale => [:en],:formats => [:pdf],:variants => [],:handlers => [:erb,:builder ,:raw,:ruby,:rabl,:rxls,:“xls.rxls”,:jbuilder]}。搜索:,我还在我的应用程序中创建了calendar_month_print.html.erb文件。我不知道我在哪里。
我的宝石文件
gem 'wicked_pdf'
gem 'wkhtmltopdf-binary'
我的控制器文件
respond_to do |format|
format.html
format.pdf do
render :pdf => "monthly_events.pdf",:template => "events/calendar_month_print.html.erb"
end
end
我的观看文件
<%= 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' %>
我的config / initializers / mime_types.rb
Mime::Type.register "application/pdf", :pdf
我的配置/初始化程序/ wicked_pdf.rb
WickedPdf.config = {
#:wkhtmltopdf => '/usr/local/bin/wkhtmltopdf',
#:layout => "pdf.html",
:exe_path => '/usr/local/bin/wkhtmltopdf'
}
答案 0 :(得分:7)
当您提供render :pdf => "monthly_events.pdf",:template => "events/calendar_month_print.html.erb"
时,Rails需要calendar_month_print.html.erb
中名为app/views/events
的文件。如果您将其放在其他位置,请将其移至app/views/events