Aston J

How to get Capistrano to ignore upload directories (Carrierwave)

Posted on: June 23rd, 2012 by AstonJ 7 Comments

As you probably know, Capistrano creates a fresh directory for your app every time you deploy a new version. So if you want some directories (or files) to be carried through to each version, such as files uploaded by users, then we just need to tell Capistrano that they are shared – and to use the /shared directory for these files instead. Which is done by creating symbolic links. Here’s how.

Add this to your deploy.rb file:

set :shared_children, shared_children + %w{public/uploads}

That will create the symbolic link. So all files uploaded to current/public/uploads actually get stored (and called from) the shared/uploads directory.

Then run deploy:setup to set it up:

cap deploy:setup

You have to make sure these directories are not tracked by Git. Which is easy enough you just add them to the .gitignore file:

# Ignore uploaded files

However, if Git is already tracking (or has previously tracked) the directory, you will need to remove it, with:

git rm -r --cached public/uploads

The –cached option doesn’t touch your working directory (so public/uploads will remain there).

That’s it! :D

Tags: , ,
  • Àlex Vinyals

    Amazing ! You are the chosen one ! Works as a charm.

  • rusllonrails

    Simple and Nice solution. It works.
    Thanks you.

  • Alexander

    Thanks you! Very useful solution.

  • marvin

    Thanks for posting a comment on Simone’s blog referencing this entry. This is more current and way easier.

  • xofred

    Thank you! Nice solve!

  • Mohamed Saleh

    Great ! Thanks.

  • Adelowo Lanre

    This is easier, i have almost knocked myself on how i’d manage my uploads before i found this