I'm in the process of upgrading my app from Rails 3.0 to Rails 3.1.
我正在将我的应用程序从Rails 3.0升级到Rails 3.1。
I've binned my old plugins in favour of gems where possible and that includes replacing the old prawnto plugin with this nice shiny new prawnto_2 gem.
在可能的情况下,我已经将我的旧插件分类为有利于宝石,包括用这个漂亮的新prawnto_2宝石替换旧的prawnto插件。
Most things seem fine, but I can't get images to load as before. The code in my PDF view is
大多数事情似乎很好,但我不能像以前一样加载图像。我的PDF视图中的代码是
pdf.image open("#{RAILS_ROOT}/public/images/logo.png")
but I get the following error
但是我收到以下错误
uninitialized constant ActionView::CompiledTemplates::RAILS_ROOT
I realise that the location of the image file will change as I'm using assets and the image is no longer stored in the public folder.
我意识到图像文件的位置会随着我使用资源而改变,并且图像不再存储在公共文件夹中。
1 个解决方案
#1
28
RAILS_ROOT
is in the global namespace, so you have to use
RAILS_ROOT位于全局命名空间中,因此您必须使用
::RAILS_ROOT
However this is deprecated, so better use
但是这已被弃用,因此请更好地使用
::Rails.root
To append a path to this, you can use this, which also works on ...erm... other operating systems
要附加到此的路径,您可以使用它,这也适用于......其他操作系统
::Rails.root.join('public','images','logo.png')
#1
28
RAILS_ROOT
is in the global namespace, so you have to use
RAILS_ROOT位于全局命名空间中,因此您必须使用
::RAILS_ROOT
However this is deprecated, so better use
但是这已被弃用,因此请更好地使用
::Rails.root
To append a path to this, you can use this, which also works on ...erm... other operating systems
要附加到此的路径,您可以使用它,这也适用于......其他操作系统
::Rails.root.join('public','images','logo.png')