Keeping uploaded files between deployments

Email this to someoneShare on Google+Share on FacebookTweet about this on TwitterShare on LinkedIn

You are using file_column plugin (or maybe another plugin?), to upload files in your ruby on rails application. Because the files are big you don’t want to have a different copy stored in your subversion repository for each different deployment version. You want to keep a common folder with all your uploaded files, and use it with every different deployment version.

For the example, we will have a numbers table that has two file_column uploadable columns (intro,voice_mail), with the following migration:

  1. If you already have used cap deploy or cap setup you should have a shared folder in your deployment server.
    You should copy the intro and vmail folders that should be located on your public/number folder on your local development client, on a folder called number in your development server in your shared folder.
  2. Create a file in your local pc in lib/cap_recipes.rb:

    Be careful with the naming of the task as (at least for capistrano 1.4 that I’m using), it must have a special name as after_symlink.
    Also be careful that if you try to use before_symlink, it won’t work as the current symlink won’t be setup.
  3. In your config/deploy.rb file add at the top the following:
  4. Now you should be ready to deploy your new version so:

    make sure that you check in your version in subversion, and then:

    you should be able to see a link in your current/public folder called number that points to the shared/number folder that hold all the uploaded files.