Pregunta

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.

¿Fue útil?

Solución

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')
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top