Ruby on Rails Monday, February 29, 2016

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

My code is this:

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>

customers_controller.erb
  def index
    @customers = Customer.all
    respond_to do |format|
      format.html
      format.pdf do
        render :pdf => 'file_name',
        :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>

And sometimes, get this error:

undefined method `start_with?' for nil:NilClass

What I 'm making wrong?



--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/43e66f09-363f-41f2-81eb-5cfc54379584%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment