Best practices for handling uploaded images and capistrano

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

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.

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

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

Thanks,
Zack

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.

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

Zack

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 :slight_smile:

Thanks again,
Zack