CSS不能在wicked_pdf中工作

时间:2022-08-23 14:35:19

I'm using the wicked_pdf and I have a problem. The css don't work. How use correctly?

我使用的是wicked_pdf,我有一个问题。css不工作。如何使用正确吗?

My code is this:

我的代码是这样的:

application.html.erb

application.html.erb

<!DOCTYPE html>
<html>
<head>
  <title>WickedPdfExample</title>
  <%= wicked_pdf_stylesheet_link_tag "bootstrap.min.css" -%>
  <%= wicked_pdf_stylesheet_link_tag "application.css" -%>
  <%= stylesheet_link_tag    'application', media: 'all', 'data-turbolinks-track' => true %>
  <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
  <%= csrf_meta_tags %>
</head>
<body>
  <div class="container">
    <%= yield %>
  </div>
</body>
</html>

layouts/pdf.html.erb

布局/ pdf.html.erb

<!DOCTYPE html>
<html>
<head>
<title>PDF</title>
  <%= wicked_pdf_stylesheet_link_tag "bootstrap" -%>
</head>
<body>

  <div class='container'>
    <%= yield %>
  </div>

</body>
</html>

customers_controller.erb

customers_controller.erb

  def index
    @customers = Customer.all
    respond_to do |format|
      format.html
      format.pdf do
        render :pdf => 'file_name',
        :layout => 'layouts/pdf.html.erb'
        :template => 'customers/index.pdf.erb',
        :show_as_html => params[:debug].present?
      end
    end
  end

index.pdf.erb

index.pdf.erb

<h1>Listing Customers</h1>

<table class="table table-condensed table-bordered">
  <thead>
    <tr>
      <th>Name</th>
      <th>Cpf</th>
      <th>Occupation</th>
    </tr>
  </thead>

  <tbody>
    <% @customers.each do |customer| %>
      <tr>
        <td><%= customer.name %></td>
        <td><%= customer.cpf %></td>
        <td><%= customer.occupation %></td>
      </tr>
    <% end %>
  </tbody>
</table>

And sometimes, get this error:

有时候,你会犯这样的错误:

undefined method `start_with?' for nil:NilClass

未定义的方法“start_with ?”零:NilClass

What I 'm making wrong?

我做错了什么?

But, my bootstrap don't charge. I tried ALL!!!

但是,我的鞋带不收费。我尝试了所有! ! !

1 个解决方案

#1


3  

I got my CSS working by this:

我的CSS工作是这样的:

<%= stylesheet_link_tag "http://#{request.host_with_port}/#{asset_path("application.css")}", rel: "stylesheet", media: "all" %>

#1


3  

I got my CSS working by this:

我的CSS工作是这样的:

<%= stylesheet_link_tag "http://#{request.host_with_port}/#{asset_path("application.css")}", rel: "stylesheet", media: "all" %>