【问题标题】:Gem wicked pdf - CSS doesn't work with rails 5Gem wicked pdf - CSS 不适用于 rails 5
【发布时间】:2017-03-03 22:53:17
【问题描述】:

我只是将我的应用程序升级到 rails 5 并且 gem wicked pdf 不再显示 css。我什么都没做,所以rails 5可能有一些规格。 如果有人发现这个问题,请随时提供帮助:)

这是我的代码:

object_controller

def download
    @object = object.find(params[:object])
    respond_to do |format|
      format.html
      format.pdf do
        render pdf:          "ptf_#{@object.id}",
               layout:       'layouts/pdf_layout',
               template:     'objects/download.html.erb',
               title:        "download object",
               show_as_html: false,
               header: { content: render_to_string(template: 'objects/header_pdf.pdf.erb'), spacing: 7  },
               footer: { content: render_to_string(template: 'objects/footer_pdf.pdf.erb'), spacing: 10 },
               margin: { top: 55, bottom: 35 }
      end
    end

pdf_layout.html.erb

<% content_for :title do %><%= @title %><% end %>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<%= wicked_pdf_stylesheet_link_tag 'pdf' %>
<br>
<%= yield %>

我尝试了两个助手 wicked_pdf_stylesheet_link_tagstylesheet_link_tag wicked_pdf_asset_base64

header_pdf.html.erb

<div class="center">
      <%= image_tag wicked_pdf_asset_base64("logo.png"), class: 'header' %>
      <div class="first-class"><%= @object.title %></div>

    </div>

这是我的一些代码摘录,只是为了向您展示我如何组织我的文件生成。我还有一个文件pdf.scss

【问题讨论】:

    标签: ruby-on-rails pdf pdf-generation ruby-on-rails-5 wicked-pdf


    【解决方案1】:

    我希望您已经找到了解决方案,但是对于其他所有人,我遇到了这个问题并通过将我的布局扩展从 .html.erb 更改为 .pdf.erb 来解决它。我的布局现在称为report.pdf.erb

    【讨论】:

    • 将 .css 文件添加到 assets.rb 对我有用
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-27
    • 2022-10-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多