我正在使用wicked_pdf而且我遇到了问题。 CSS不起作用。如何正确使用?
我的代码是:
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>
布局/ 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
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
<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>
有时,会收到此错误:
未定义的方法`start_with?'为零:NilClass
我做错了什么?
但是,我的引导程序不会充电。我试过了所有!!!
答案 0 :(得分:4)
我的CSS工作原理:
<%= stylesheet_link_tag "http://#{request.host_with_port}/#{asset_path("application.css")}", rel: "stylesheet", media: "all" %>