Trip Trip - 4 months ago 13
Ruby Question

How do you access your images folder from a controller?

I'm setting up Prawn right now and for one param it wants to know the img location.

In their case they wrote :

img = "#{Prawn::BASEDIR}/data/images/card_cutout.jpg"


But that points to a local gems folder. How can I make this from the controller point to
card_cutout.jpg
in my public/images/ folder.

I tried using an absolute link thinking it would work like a website but I was wrong :

img = "http://www.website.com/images/card_cutout.jpg


Thanks in advance!

Answer

Try this:

img = "#{Rails.root/public/images/card_cutout.jpg}"