【发布时间】:2016-06-05 12:14:24
【问题描述】:
将chartkick 与wicked-pdf 一起使用。
app/layout/pdf.html.erb
<!doctype html>
<html>
<head>
<meta charset='utf-8' />
<%= wicked_pdf_stylesheet_link_tag 'application', media: 'all' %>
<%= wicked_pdf_javascript_include_tag 'application', 'data-turbolinks-track' => true %>
<%= javascript_include_tag "http://www.google.com/jsapi"%>
<%= wicked_pdf_javascript_include_tag 'chartkick'%>
</head>
<body onload='number_pages'>
<div id="header">
<h2>Report</h2>
</div>
<div id="content">
<%= yield %>
</div>
但它在这条线上给出了一个错误
<%= wicked_pdf_stylesheet_link_tag 'application', media: 'all' %>
错误
undefined method `start_with?' for nil:NilClass
我如何删除它? 错误
ActionView::Template::Error (undefined method `start_with?' for nil:NilClass):
2: <html>
3: <head>
4: <meta charset='utf-8' />
5: <%= wicked_pdf_stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
6: <%= wicked_pdf_javascript_include_tag 'application', 'data-turbolinks-track' => true %>
7: <%= javascript_include_tag "http://www.google.com/jsapi"%>
8: <%= wicked_pdf_javascript_include_tag 'chartkick'%>
app/views/layouts/pdf.html.erb:5:in `_app_views_layouts_pdf_html_erb___3130978149028204091_70042742447040'
app/controllers/campaigns_controller.rb:104:in `block (2 levels) in survey_reporting'
app/controllers/campaigns_controller.rb:101:in `survey_reporting'
【问题讨论】:
-
你能发布更多的堆栈跟踪吗?
-
那个错误告诉你你正在调用start_with?在你期望有一个值但实际上等于
nil的东西上,可能是因为它是一个你认为你已经定义但实际上没有定义的实例变量。堆栈跟踪将具体告诉您发生这种情况的位置。查找项目文件夹中的第一行而不是 gem。 -
@HaseebAhmad - 如果您在浏览器中看到此错误,请单击“完整堆栈跟踪”并发布您将获得的内容。
-
@HaseebAhmad - 你没有碰巧覆盖
WickedPdfHelper::Assets::ASSET_URL_REGEX常量,是吗? github.com/mileszs/wicked_pdf/blob/master/lib/wicked_pdf/… 想不出可以返回 nil 的场景。 -
有一个官方 issue 解决这个问题:github.com/mileszs/wicked_pdf/issues/470
标签: ruby-on-rails wicked-pdf chartkick