wicked_pdf: ActionView::Template::Error (undefined method `start_with?' for nil:NilClass):

I am having this error undefined method `start_with?’ - I don’t understand what this means. where am i loading a nil object?

I, [2015-12-01T22:21:00.925951 #5340]  INFO -- : ***************WICKED***************
I, [2015-12-01T22:21:01.102353 #5340]  INFO -- :   Rendered orders/show.erb (175.6ms)
I, [2015-12-01T22:21:01.102604 #5340]  INFO -- : Completed 500 Internal Server Error in 178ms (Models: 0.2ms)
F, [2015-12-01T22:21:01.103737 #5340] FATAL -- : 
    ActionView::Template::Error (undefined method `start_with?' for nil:NilClass):
        2: <html>
        3:   <head>
        4:     <meta charset='utf-8' />
        5:     <%= wicked_pdf_stylesheet_link_tag 'application' %>
        6:     <%= wicked_pdf_javascript_include_tag 'application' %>
        7:   </head>
        8:   <body onload='number_pages'>
      app/views/orders/show.erb:5:in `_app_views_orders_show_erb__4409957572708346332_51152780'
      app/controllers/orders_controller.rb:51:in `block (2 levels) in show'
      app/controllers/orders_controller.rb:48:in `show'

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Comments: 30

Most upvoted comments

I resolved this issue by adding @import "bootstrap-sprockets" before @import "bootstrap"

I got it! A better solution was by doing the steps in this Stackoverflow thread

Then, add the a line for you bootstrap.css file location in your config/application.rb. It should look like this:

config.assets.paths << "#{Rails.root}/app/assets/stylesheets/font-awesome-4.2.0/css/" `
config.assets.paths << "#{Rails.root}/app/assets/stylesheets/bootstrap/" `
config.assets.paths << "#{Rails.root}/vendor/assets/fonts" `

And, finally add a import for bootstrap in your pdf.css.scss file. It should look like this:

@import "bootstrap";
@import "font-awesome";
@import "estilo";

We found some commented out url’s in our css files that the wicked regex picked up. Removing these resolved this issue for us.

Hi, I’m having the exactly same problem, but it only happens when I tried to @import "bootstrap/bootstrap.min"; at my pdf.css.scss file. If I don’t put the @import "bootstrap/bootstrap.min", it works! The pdf inherit the font-awesome style and my custom style “estilo”.

@import "font-awesome"; @import "estilo";

But… I really need the bootstrap.

I’ve already tried to import the Bootstrap CDN url at my pdf.css.scss file, I don’t get this error in the topic, but my generated PDF don’t inherit the bootrstrap css.

Could anyone help?

Relative links and imports won’t be able to resolve when being served from the filesystem when using the WickedPdf asset helpers (which tries to transform relative paths to filesystem paths, but not always, like for @import statements. Either switch to the normal Rails asset helpers (which can be much slower when generating PDFs), or use absolute imports and CSS preprocessing to do something like this:

@import "<%= Rails.root.join('vendor/assets/font-awesome.css').to_s %>";

If you use SASS, it will automatically inline @import statements.

@Chaoste Thanks for this! I finally had to upgrade the gem so I came back here and saw your post. Solved the problem for me and shouldn’t break anything! 👍