Problem when rendering pdfs in rails 4 in development mode

1

use the library wicked_pdf the problem is in the call to the styles, I am new in rails attached an image

this is my layout

<html>
<head>
<meta charset="utf-8" />
<%= wicked_pdf_stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true  -%>
<%= wicked_pdf_javascript_include_tag "application" %>
<%= csrf_meta_tags %>
<style>
  body {font-size: 9px !important;}
  h3 {font-size: 10px !important; font-weight: bold; margin-top: 2px; margin-bottom: 2px; text-align: center;}
  table, tr, td, th, tbody, thead, tfoot {
    page-break-inside: avoid !important;
  }
  h2 {font-size: 13px !important;}
  p {font-size: 9px !important; text-align: justify;}
  .float-right {float: right; font-weight: bold;}
  p span {font-weight: bold;}
  .contract-signer{
    margin-top: 70px;
  }
  .contract-signer p{
    text-align: center;
  }
  #brake{
    display: block;
    clear: both;
    page-break-before: always;
  }
  table, th, td {
      border: 1px solid black !important;
      margin: 0 !important;
      padding: 4px !important;
  }
  div.alwaysbreak { page-break-before: always; }
  div.nobreak:before { clear:both; }
  div.nobreak { page-break-inside: avoid; }
</style>
<script>
  function number_pages() {
    var vars={};
    var x=document.location.search.substring(1).split('&');
    for(var i in x) {var z=x[i].split('=',2);vars[z[0]] = decodeURIComponent(z[1]);}
    var x=['frompage','topage','page','webpage','section','subsection','subsubsection'];
    for(var i in x) {
      var y = document.getElementsByClassName(x[i]);
      for(var j=0; j<y.length; ++j) y[j].textContent = vars[x[i]];
    }
  }
</script>

    Contract          <% = yield% >     

But when I run in production mode, does any help go well?

    
asked by Darlyncinho Bravo 24.09.2016 в 01:51
source

1 answer

2

You have a script at the end of the line. Instead of:

<%= wicked_pdf_stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true  -%>

is:

<%= wicked_pdf_stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>

P.S. : please for the next question, copy / paste the error instead of taking a screenshot. It is something much easier to handle, apart from that it can be easily read without the need for a magnifying glass. Greetings

Update:

Reviewing the issues of the gem , there seems to be a problem in how wicked_pdf interprets the url of the assets which are accessed through the command url() of css. Some have had the error by bootstrap, others by font awesome, others in their own custom css where they have used url . What I recommend so you can debug the error:

  • You comment that it does not give you problems in production, that may be due to the fact that the assets are already compiled and can be accessed. You could try to do a local compilation of your assets with rake assets:precompile and see if you still get the error.
  • Check your application.css and go commenting each one of your require (or @import in case you are using sass) to see which css is the one that is giving you problems. When you can identify it, look for a call to url and evaluate if it is being used in your generated pdf to delete it from the css.
  • In case you can not delete the calls to url of the css, because it would affect the styles of the website in general, consider creating a css file different from application.css , something like <%= wicked_pdf_stylesheet_link_tag 'pdf' %> where they are loaded only the styles to use within the generation of the pdf.
answered by 24.09.2016 / 15:46
source