ruby-on-railspdfprincexmlprincely

Not finding images when generating pdf's with Prince using the Princely plugin Rails 4.2.1


I have a bunch of images in app/assets/images/ when I render the html view the images are present as one would expect. When I render the pdf view via princely they are not present I just get something like this: Bd header70 b cc0e9cd02bd0b2ec1f31f22bbfe90be47fec42de002e9f5445603b82b492bdaa

In my controller I have this (as per the Princely Github page):

 render pdf => 'ConsultantsQuote',
 :template => 'quotes/show_consultant',
 :handlers => %w[erb],
 :formats => %w[pdf],
 :stylesheets => %w[application pdf],
 :layout => 'pdf',
 :disposition => 'inline',
 :relative_paths => true

In my view: <%= image_tag("bd_header70_b.png") %>

The path seems to be wrong, see the snippet frome the Prince log below:

Mon Sep 28 08:59:43 2015: /home/pjt/Q2/public//assets/bd_header70_b-cc0e9cd02bd0b2ec1f31f22bbfe90be47fec42de002e9f5445603b82b492bdaa.png: warning: can't open input file: No such file or directory

The path should be: /home/pjt/Q2/app/assets/images/bd_header70_b-cc0e9cd02bd0b2ec1f31f22bbfe90be47fec42de002e9f5445603b82b492bdaa.png Rails 4 no longer stores images in /home/pjt/Q2/public/ and I do not understand the "//" at all.

I'm using Ubuntu 14.04, Prince 10 and the Princely plugin and I'm in development mode.

Help with this will be very greatly appreciated.


Solution

  • The solution to the above problem was quite simple once I twigged. The problem is that while running in dev mode your assets are not really pre-compiled, thus the path in /public/... doesn’t really exist, it’s just internally mapped to the file in app/assets/images/.... So run rake assets:precompile and that will generate the needed.

    Be aware you will need to run rake assets:clobber (Rails 4) or rake assets:clean (Rails 3.2) iirc before making any changes to your JS/CSS otherwise your changes won’t be visible and then of cause run rake assets:precompile again.