Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/32.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Css Wicked_pdf样式表不适用于Heroku_Css_Ruby On Rails_Pdf_Heroku_Wicked Pdf - Fatal编程技术网

Css Wicked_pdf样式表不适用于Heroku

Css Wicked_pdf样式表不适用于Heroku,css,ruby-on-rails,pdf,heroku,wicked-pdf,Css,Ruby On Rails,Pdf,Heroku,Wicked Pdf,我有一个Rails应用程序,我使用wicked_pdf生成pdf。这一切都很好,可以在本地工作,但当推送到heroku时,PDF会呈现,但不应用样式表 特别是对于PDF渲染,我有一个CSS文件:app/assets/stylesheets/PDF.CSS.scss。在form.pdf.haml中,我像这样加载样式表: !!! %html{lang: "en", "xml:lang" => "en", xmlns: "http://www.w3.org/1999/xhtml"}

我有一个Rails应用程序,我使用wicked_pdf生成pdf。这一切都很好,可以在本地工作,但当推送到heroku时,PDF会呈现,但不应用样式表

特别是对于PDF渲染,我有一个CSS文件:
app/assets/stylesheets/PDF.CSS.scss
。在
form.pdf.haml
中,我像这样加载样式表:

  !!!
  %html{lang: "en", "xml:lang" => "en", xmlns: "http://www.w3.org/1999/xhtml"}
    %head
      %meta{content: "text/html; charset=UTF-8", "http-equiv" => "Content-Type"}/
      = wicked_pdf_stylesheet_link_tag "pdf"
如前所述,它在本地工作得很好,但当推到heroku时,我得到以下错误:

ActionView::Template::Error (No such file or directory - /app/public/pdf.css)
我要怎么做才能在heroku上工作


编辑:我找到了这个Gihub回购
https://github.com/jordan-brough/heroku-pdf
,这是在heroku上使用wicked_pdf的示例应用程序。在请求PDF时,通过调整
环境.rb
来提供
公共文件夹中的css文件,这确实很有帮助。

wkhtmltopdf二进制文件可以在heroku上运行,而无需在自己的存储库中安装任何二进制文件。它还附带了用于开发的OSX(darwin)二进制文件。它与PDFKit一起工作,可能也应该与WickedPDF一起工作

https://github.com/bradphelan/wkhtmltopdf-heroku

  or in your Gemfile as
    gem "wkhtmltopdf-heroku"
我尝试了这个解决方案,结果
wicked\u pdf
奏效了。但评论说:

“激活运行时编译不是解决方案,因为 我们取得了表演成功“@David Tuite


并在
非愚蠢摘要资产
gem的评论中找到了答案,效果非常好。

我也遇到了类似的问题,我花了一段时间才破解。最后,除了正确处理调试选项外,我还使用了gem和以下设置,这些设置在本地和heroku上都有效:

在控制器中:

在show.pdf.erb中:

在config/initializers/assets.rb中


希望这将对其他人有所帮助。

二进制文件不是这里的问题,它可以很好地呈现PDF格式,只是没有css文件。这个宝石只添加了二进制。谢谢。这个给我修好了!非常有用。这应该在wicked_pdf的
README.md
上。
respond_to do |format|
  format.html
  format.pdf do
    render pdf: @profile.name + Date.today.to_s(:number),
           background: true,
           encoding: 'utf8',
           :show_as_html => params[:debug].present?
  end
end
<% if params[:debug].present? %>
  <%= stylesheet_link_tag 'documents' %>
<% else %>
  <%= wicked_pdf_stylesheet_link_tag 'documents' %>
<% end %>
... rest of view ...
config.assets.precompile += ['documents.css.scss.erb']
Rails.application.config.assets.precompile += %w( documents.css )