RAILS_ROOT not longer valid when loading images with the prawnto_2 gem
Asked Answered
T

1

9

I'm in the process of upgrading my app from Rails 3.0 to 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.

Most things seem fine, but I can't get images to load as before. The code in my PDF view is

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.

Timepiece answered 8/2, 2012 at 11:54 Comment(0)
C
28

RAILS_ROOT is in the global namespace, so you have to use

::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')
Caucasus answered 8/2, 2012 at 11:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.