Forum How do I...?

Rails 4.2.1 Images do not show in generated pdf

sailorxyz
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:

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") %>

What am I doing wrong?

Thanks Paul Thompson
mikeday
Can you capture the HTML that is being passed to Prince?
sailorxyz
Hi Mike,

See the attached file which is all the html code. No images appear in the pdf but there are no issues when the code is rendered in the browser.

Thank you.
  1. show_consultant.pdf.erb5.4 kB
    Requested html file
mikeday
This is not HTML though, the template has not been expanded yet:
<%= image_tag("bd_header70_b.png") %>
sailorxyz
Mike, I've no idea how to get the expanded html. if you could advise me as to how, I'll get it.
mikeday
Does this StackOverflow post help?

Are there any warnings showing up in the Prince log?
sailorxyz
Hi Mike, where do I find the Prince logs, I'm using Prince 10 on Ubuntu 14.04. Thank you.

BTW: The prince logs appear in the logs folder inside your parent Rails folder... discovered that when I went looking!

Edited by sailorxyz

sailorxyz

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 after making your changes, run rake assets:precompile again.

Edited by sailorxyz