Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RAILS_ROOT not longer valid when loading images with the prawnto_2 gem

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.

like image 399
Simmo Avatar asked Feb 08 '12 11:02

Simmo


1 Answers

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')
like image 159
iblue Avatar answered Oct 11 '22 12:10

iblue