Mr. Black
Mr. Black

Reputation: 12122

How can I display an image whose path is outside my Ruby on Rails project directory

how to display the image, which is stored in outside from the project directory.

Upvotes: 3

Views: 901

Answers (3)

moritz
moritz

Reputation: 25767

You can do two things: Either you symlink to the file from within your public folder and serve the image as a static asset, or you read the image with File.read(/path/to/file) and send the binary data with send_file or send_data from within your controller.

The first option can also be slightly modified: you could catch the request for the image with a rails controller action and serve it to the browser. Additionally you could add the symlink and have the file served statically from then on.

I hope, this helps.

Upvotes: 5

Hitesh
Hitesh

Reputation: 825

if you want to give image path out of project directory, you should have server root directory path and image_folderpath for example image folder is available at /home/ror/image_folder like that, you can access from that directory

Upvotes: 0

TH Afridi
TH Afridi

Reputation: 432

it is not recommended simply copy the image into your public image directory and use it. However it uses the relative path so it will be difficult for the image outside of the project directory to be displayed but you can upload the image and copy the url and then can use that url but this is also not a good approach.

Upvotes: 2

Related Questions