# Folders and files outside of ROOT

**URL:** <https://www.ruby-forum.com/t/folders-and-files-outside-of-root/112153>\
**Category:** Rails\
**Created:** [August 15, 2007, 11:12pm UTC](https://www.ruby-forum.com/t/folders-and-files-outside-of-root/112153 "2007-08-15T23:12:52Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![fernando](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/779978/32.png) [@fernando](https://www.ruby-forum.com/u/fernando)\
**Post date:** [August 15, 2007, 11:12pm UTC](https://www.ruby-forum.com/t/folders-and-files-outside-of-root/112153/1 "2007-08-15T23:12:52Z")

</div>

Hi,  
My problem is similar to:  
[http://groups.google.co.uk/group/rubyonrails-talk/browse\_thread/thread/783a7821b13517ca/8c9543e2e6e79472?lnk=gst&q=outside+the+root&rnum=2&hl=en](http://groups.google.co.uk/group/rubyonrails-talk/browse_thread/thread/783a7821b13517ca/8c9543e2e6e79472?lnk=gst&q=outside+the+root&rnum=2&hl=en)

I am using attachment\_fu to allows users to upload their own images.  
However I want to store them outside of my applications root. Then,  
when I ‘cap deploy’, I wont wipe them all. I can then  
use :after\_update\_code to set a symlink and just update that with each  
deployment.

Does anyone know of a solution?  
Rails seems to always look inside ‘public/images’ and I know that you  
can use the plugin ‘multi-asset-locations’ to set a particular  
asset\_host for images but I didn’t quite understand how:  
:images =\> “[http://images.domain.com](http://images.domain.com)”  
relates to a particular folder on the site??

Any nods in the right direction would be much appreciated.

Cheers,  
Tim

---

<div class="post-metadata">

**Author:** ![fernando](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/779978/32.png) [@fernando](https://www.ruby-forum.com/u/fernando)\
**Post date:** [August 15, 2007, 11:27pm UTC](https://www.ruby-forum.com/t/folders-and-files-outside-of-root/112153/2 "2007-08-15T23:27:55Z")

</div>

What we did is wrote a simple controller that handles the mechanics  
of reading a binary file and pumping it out as the response.

def get\_asset  
asset = FileAsset.find(params[:id])  
disposition = ‘attachment’  
if asset.mime\_type == ‘image/x-png’ or  
asset.mime\_type == ‘image/gif’ or asset.mime\_type == ‘image/jpeg’ :  
disposition = ‘inline’  
end  
send\_file asset.file\_path, :type =\>  
asset.mime\_type, :disposition =\> disposition  
end

---

<div class="post-metadata">

**Author:** ![fernando](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/779978/32.png) [@fernando](https://www.ruby-forum.com/u/fernando)\
**Post date:** [August 17, 2007, 8:32pm UTC](https://www.ruby-forum.com/t/folders-and-files-outside-of-root/112153/3 "2007-08-17T20:32:27Z")

</div>

Just for other people suffering the same problem. I used a hack in the  
end to copy all the images from a folder in my application to one  
outside the application. THEN updated the code, THEN copied it back.  
All done using capistrano tasks:

task :before\_deploy do  
run “cp -r /home/domainName/appName/current/trunk/public/  
image\_uploads/\* /home/domainName/image\_backup/”  
end

task :after\_deploy, :roles =\> [:app, :db, :web] do  
run “cp -r /home/domainName/image\_backup/\* /home/domainName/appName/  
current/trunk/public/image\_uploads/”  
run “rm -rf /home/domainName/image\_backup/\*”  
end

Hope someone finds that useful.
