Forum: Ruby on Rails best practices for handling uploaded images and capistrano

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Zack C. (Guest)
on 2006-03-08 18:02
(Received via mailing list)
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
Roberto S. (Guest)
on 2006-03-08 18:12
(Received via mailing list)
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.
Bradley T. (Guest)
on 2006-03-08 20:22
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
Zack C. (Guest)
on 2006-03-09 00:41
(Received via mailing list)
Bradley,
  Perfect.  I'll give this a go - thanks a ton!

Zack
Zack C. (Guest)
on 2006-03-09 00:44
(Received via mailing list)
Roberto,
  Thanks. I'll take a look at the after tasks...
  What did you mean by "put the uploaded files into shared..."

Thanks,
Zack
Tom M. (Guest)
on 2006-03-09 01:27
(Received via mailing list)
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.
Zack C. (Guest)
on 2006-03-09 18:46
(Received via mailing list)
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
This topic is locked and can not be replied to.