# Best practices for handling uploaded images and capistrano

**URL:** <https://www.ruby-forum.com/t/best-practices-for-handling-uploaded-images-and-capistrano/54560>\
**Category:** Rails\
**Created:** [March 8, 2006, 5:02pm UTC](https://www.ruby-forum.com/t/best-practices-for-handling-uploaded-images-and-capistrano/54560 "2006-03-08T17:02:49Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Zack\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/eb9ed0/32.png) [@Zack\_C](https://www.ruby-forum.com/u/Zack_C)\
**Post date:** [March 8, 2006, 5:02pm UTC](https://www.ruby-forum.com/t/best-practices-for-handling-uploaded-images-and-capistrano/54560/1 "2006-03-08T17:02:49Z")

</div>

Quick question: I am going to use the file\_column plugin to manage  
uploading  
thumbnails. By default the images are stored in the public/ dir of the  
rails project. The problem I see is that when capistrano redeploys a  
new  
build and symlinks it in none of the images will be in the new public/  
dir… Does anyone have a solution for this?

Thanks,  
Zack

---

<div class="post-metadata">

**Author:** ![Zack\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/eb9ed0/32.png) [@Zack\_C](https://www.ruby-forum.com/u/Zack_C)\
**Post date:** [March 8, 2006, 5:12pm UTC](https://www.ruby-forum.com/t/best-practices-for-handling-uploaded-images-and-capistrano/54560/2 "2006-03-08T17:12:00Z")

</div>

Put the directory with the uploaded files into “shared” and just symlink  
it  
from within public to there. To automate that you can use the  
after\_symlink  
filter to create your custom capistrano task. IF you take a closer look  
at  
how capistrano works, you see that the same happens with the logfile  
directories.

---

<div class="post-metadata">

**Author:** ![Zack\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/eb9ed0/32.png) [@Zack\_C](https://www.ruby-forum.com/u/Zack_C)\
**Post date:** [March 8, 2006, 7:22pm UTC](https://www.ruby-forum.com/t/best-practices-for-handling-uploaded-images-and-capistrano/54560/3 "2006-03-08T19:22:13Z")

</div>

Zack C. wrote:

> Quick question: I am going to use the file\_column plugin to manage  
> uploading  
> thumbnails. By default the images are stored in the public/ dir of the  
> rails project. The problem I see is that when capistrano redeploys a  
> new  
> build and symlinks it in none of the images will be in the new public/  
> dir… Does anyone have a solution for this?

This solution should work. I didn’t test it but it should be close.

Set an array to hold a list of model object names that have  
file\_columns:

set :models, %w( model\_one model\_two )

Create the shared directories to store images for the models that use  
file\_column:

task :after\_setup, :roles =\> [:app, :web] do  
models.each { |model| run “mkdir -p #{shared\_path}/public/#{model}”  
}  
end

Create the links:

task :after\_symlink, :roles =\> [:app, :web] do  
models.each { |model| run “ln -nfs #{shared\_path}/public/#{model}  
#{current\_path}/public/#{model}” }  
end

Remember to ignore the image directories in your svn repository so you  
don’t add stuff from your local development machine. Good luck!

Bradley Taylor

* * *

Rails Machine  
Simplified web application deployment  
[http://railsmachine.com](http://railsmachine.com)

---

<div class="post-metadata">

**Author:** ![Zack\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/eb9ed0/32.png) [@Zack\_C](https://www.ruby-forum.com/u/Zack_C)\
**Post date:** [March 8, 2006, 11:44pm UTC](https://www.ruby-forum.com/t/best-practices-for-handling-uploaded-images-and-capistrano/54560/4 "2006-03-08T23:44:34Z")

</div>

Roberto,  
Thanks. I’ll take a look at the after tasks…  
What did you mean by “put the uploaded files into shared…”

Thanks,  
Zack

---

<div class="post-metadata">

**Author:** ![Zack\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/eb9ed0/32.png) [@Zack\_C](https://www.ruby-forum.com/u/Zack_C)\
**Post date:** [March 9, 2006, 12:27am UTC](https://www.ruby-forum.com/t/best-practices-for-handling-uploaded-images-and-capistrano/54560/5 "2006-03-09T00:27:11Z")

</div>

Capistrano creates a directory structure that includes:

current (symlink into releases)  
releases  
shared  
log  
system  
photos \<-- (or something similar is where Roberto was suggesting.

In addition to Roberto’s spot-on advice, I’d suggest adding the  
symlinks into the Subversion repository, as it will then be one  
fewer step to think about.

–  
– Tom M.

---

<div class="post-metadata">

**Author:** ![Zack\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/eb9ed0/32.png) [@Zack\_C](https://www.ruby-forum.com/u/Zack_C)\
**Post date:** [March 8, 2006, 11:41pm UTC](https://www.ruby-forum.com/t/best-practices-for-handling-uploaded-images-and-capistrano/54560/6 "2006-03-08T23:41:22Z")

</div>

Bradley,  
Perfect. I’ll give this a go - thanks a ton!

Zack

---

<div class="post-metadata">

**Author:** ![Zack\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/eb9ed0/32.png) [@Zack\_C](https://www.ruby-forum.com/u/Zack_C)\
**Post date:** [March 9, 2006, 5:46pm UTC](https://www.ruby-forum.com/t/best-practices-for-handling-uploaded-images-and-capistrano/54560/7 "2006-03-09T17:46:25Z")

</div>

Tom,  
Thanks for clearing that up. I’m not to the deploying step yet so I  
haven’t looked with depth at Capistrano yet - I just know that it will  
be  
the tool to use. It sounds like I should investigate it soon as it  
pertains  
to my immediate image upload needs 🙂

Thanks again,  
Zack
