简体   繁体   English

使用Princely插件Rails 4.2.1与Prince生成pdf时找不到图像

[英]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. 当我渲染html视图时,我在app / assets / images /中有一堆图像。 When I render the pdf view via princely they are not present I just get something like this: Bd header70 b cc0e9cd02bd0b2ec1f31f22bbfe90be47fec42de002e9f5445603b82b492bdaa 当我通过王子渲染pdf视图时,它们不存在,我得到的是这样的东西:Bd header70 b cc0e9cd02bd0b2ec1f31f22bbfe90be47fec42de002e9f5445603b82b492bdaa

In my controller I have this (as per the Princely Github page): 在我的控制器中,我有这个(根据Princely Github页面):

 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") %> 在我看来:<%= image_tag(“ bd_header70_b.png”)%>

The path seems to be wrong, see the snippet frome the Prince log below: 路径似乎有误,请参见下面的Prince日志中的摘录:

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 2015年9月28日星期一08:59:43:/home/pjt/Q2/public//assets/bd_header70_b-cc0e9cd02bd0b2ec1f31f22bbfe90be47fec42de002e9f5445603b82b492bdaa.png:警告:无法打开输入文件:无此类文件或目录

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. 路径应为:/home/pjt/Q2/app/assets/images/bd_header70_b-cc0e9cd02bd0b2ec1f31f22bbfe90be47fec42de002e9f5445603b82b492bdaa.png Rails 4不再将图像存储在/ home / pjt / Q2 / public /中,我不理解所有。

I'm using Ubuntu 14.04, Prince 10 and the Princely plugin and I'm in development mode. 我正在使用Ubuntu 14.04,Prince 10和Princely插件,并且处于开发模式。

Help with this will be very greatly appreciated. 帮助将不胜感激。

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. 问题在于,在开发人员模式下运行时,您的资产并未真正进行预编译,因此/ public / ...中的路径实际上并不存在,它只是内部映射到app / assets / images /中的文件。 ..因此运行rake asset:precompile会生成所需的。

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. 请注意,在对JS / CSS进行任何更改之前,您需要先运行rake asset:clobber (Rails 4)或rake asset:clean (Rails 3.2)iirc,否则您的更改将不可见,从而导致运行rake asset:再次预编译

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM