# Using absolute paths for images

**URL:** <https://www.ruby-forum.com/t/using-absolute-paths-for-images/140222>\
**Category:** Rails\
**Created:** [June 12, 2008, 1:01am UTC](https://www.ruby-forum.com/t/using-absolute-paths-for-images/140222 "2008-06-12T01:01:05Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![adam](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/4af34b/32.png) [@adam](https://www.ruby-forum.com/u/adam)\
**Post date:** [June 12, 2008, 1:01am UTC](https://www.ruby-forum.com/t/using-absolute-paths-for-images/140222/1 "2008-06-12T01:01:05Z")

</div>

Hi all,

I want to make images stored on my filesystem available to a Rails  
app, even if they are outside the Rails directory. For example, if my  
app is in /home/adam/rails\_app/my\_app I want to display an image from /  
home/adam/Pictures without having to copy the picture into the app  
public/images directory. When I try this, using the absolute path of  
the file, I get a routing error:

ActionController::RoutingError (No route matches “/home/adam/Pictures/  
my\_pic.jpg” with {:method=\>:get})

This is using image\_tag with an absolute file path “/home/adam/  
Pictures/my\_pic.jpg”. Even if I use a simple HTML img tag, the image  
is not displayed. Is it possible to bypass Rails routing and get  
access to these files?

Many thanks,  
Adam

---

<div class="post-metadata">

**Author:** ![adam](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/4af34b/32.png) [@adam](https://www.ruby-forum.com/u/adam)\
**Post date:** [June 12, 2008, 1:04am UTC](https://www.ruby-forum.com/t/using-absolute-paths-for-images/140222/2 "2008-06-12T01:04:43Z")

</div>

On Jun 11, 2008, at 4:00 PM, Adam wrote:

> I want to make images stored on my filesystem available to a Rails  
> app, even if they are outside the Rails directory. For example, if my  
> app is in /home/adam/rails\_app/my\_app I want to display an image  
> from /  
> home/adam/Pictures without having to copy the picture into the app  
> public/images directory. When I try this, using the absolute path of  
> the file, I get a routing error:

I use symbolic links to similarly deal with download files. I don’t  
want the downloads to be part of the Rails project, so they’re  
managed separately under another path. To make them available to  
Rails, I put a symbolic link in the /public folder. Your deploymemt  
script can deal with refreshing the symbolic link each time the app  
is updated/redeployed.

– gw

---

<div class="post-metadata">

**Author:** ![adam](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/4af34b/32.png) [@adam](https://www.ruby-forum.com/u/adam)\
**Post date:** [June 12, 2008, 8:14am UTC](https://www.ruby-forum.com/t/using-absolute-paths-for-images/140222/3 "2008-06-12T08:14:09Z")

</div>

you can set a default root directory if there is only one folder for all  
the images outside ur rails app

but i would recommend you to put the image in the same application since  
if you are going to deploy that going forward…thats the right method to  
do…

Dhaval P.  
Software Engineer

> **[RailsHouse : Ruby on Rails Development & Consulting, Waterloo, Canada](https://railshouse.com)**
>
> RailsHouse is Waterloo, Ontario based Ruby on Rails Consultancy firm which provides RoR Development, Migration, Staffing, Maintenace and Support Services

sales(AT)railshouse(DOT)com

---

<div class="post-metadata">

**Author:** ![adam](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/4af34b/32.png) [@adam](https://www.ruby-forum.com/u/adam)\
**Post date:** [June 12, 2008, 1:29am UTC](https://www.ruby-forum.com/t/using-absolute-paths-for-images/140222/4 "2008-06-12T01:29:24Z")

</div>

A solution would be apache frontend and using Alias

Alias /my\_images /this/is/the/images/directory  
\<Directory “/this/is/the/images/directory”\>  
Options FollowSymLinks  
AllowOverride None  
Order allow,deny  
Allow from all

This will remove the image handling from rails and let apache do what  
apache does…

---

<div class="post-metadata">

**Author:** ![adam](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/4af34b/32.png) [@adam](https://www.ruby-forum.com/u/adam)\
**Post date:** [June 12, 2008, 12:14pm UTC](https://www.ruby-forum.com/t/using-absolute-paths-for-images/140222/5 "2008-06-12T12:14:01Z")

</div>

Thanks all, symlinks worked perfectly for what I’m trying to do.

On 12 Jun, 07:14, Dhaval P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
