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:
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:
You have to make sure these directories are not tracked by Git. Which is easy enough you just add them to the .gitignore file:
However, if Git is already tracking (or has previously tracked) the directory, you will need to remove it, with:
The –cached option doesn’t touch your working directory (so public/uploads will remain there).
That’s it! 😀