我已经使用wicked pdf gem for html to pdf generate in rails 4.它对我不起作用,它会像我这样抛出错误 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: 而且我还在我的应用程序中创建了calendar_month_print.html.erb文件 . 我不知道't know where i' m .
我的宝石文件
gem 'wicked_pdf'
gem 'wkhtmltopdf-binary'
我的Controller文件
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
我的config / initializers / wicked_pdf.rb
WickedPdf.config = {
#:wkhtmltopdf => '/usr/local/bin/wkhtmltopdf',
#:layout => "pdf.html",
:exe_path => '/usr/local/bin/wkhtmltopdf'
}
1 回答
当您给出
render :pdf => "monthly_events.pdf",:template => "events/calendar_month_print.html.erb"
时,Rails需要app/views/events
中名为calendar_month_print.html.erb
的文件 . 如果你把它放在别的地方,那么把它移到app/views/events