how-to display an image living outside the public directory

I'm trying to display an image (chart) that lives outside the public directory in RAILS_ROOT/private.

The chart contains confidential information and so can't live in /public or any sub-directories of /public.

The chart needs to be displayed from a partial. The first display of the page containing the partial is an html render. Subsequently, the user can select a different chart causing an ajax call which replaces the content of the image-containing dom element in the partial with a new chart image.

Any thoughts / pointers are much appreciated!

Best regards, Bill

bill walton wrote:

I'm trying to display an image (chart) that lives outside the public directory in RAILS_ROOT/private.

You probably looking for send_file:

http://railsapi.com/doc/rails-v2.3.5/classes/ActionController/Streaming.html#M001587

Hi Rob,

You could have PrivateImagesController with show method

and you will get your images through /private_images/image_name.png

in show method

(check permissions) send_file “#{RAILS_ROOT}/private_images_folder/#{params[:image_name]}”

send_file is really slow and will work only when there’s not a lot of users requesting files

In Nginx you could use x-send-file option or something, which makes send_file work much better. I didn’t try that though.