Orsay
Orsay

Reputation: 1130

Gem wicked pdf - CSS doesn't work with rails 5

I just upgrade my application to rails 5 and the gem wicked pdf doesn't display css anymore. I changed nothing, so there're may be some specifications with rails 5. If anybody figure out this problem feel free to help :)

Here is my code :

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 %>

I tried with both helpers wicked_pdf_stylesheet_link_tag and stylesheet_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>

This is a few extract of my code just to show you how I organize my file generation. I also have a file pdf.scss

Upvotes: 4

Views: 1901

Answers (1)

Bob Farrell
Bob Farrell

Reputation: 46

I hope you already found a solution but, for everyone else, I hit this problem and resolved it by changing the extension of my layout from .html.erb to .pdf.erb. My layout is now called report.pdf.erb.

Upvotes: 3

Related Questions