How do I symlink my product images in production on a Capistrano deploy?

Here I received a solution to my problem that every time when I deploy my Spree Commerce app with Capistrano my images are removed (they are still there, but the folder names are wrong) and I have to add them again via admin.

Both on this Google group and in the answer to the question it is said that symlinking is solution.

You need to make sure that your RAILS_ROOT/public/spree directory is
being symlinked in from the Capistrano shared directory and not
recreated every time you deploy. If this symlink isn’t happening, your
images will be lost on every deploy.

I’ve tried a few things but I do not manage to symlink my images.

On the server they are in the folder /public/spree/products. What I tried is this:

namespace :deploy do
  task :start do ; end
  task :stop do ; end
  task :symlink_shared do
     run "ln -nfs #{shared_path}/shared/spree/ #{release_path}/public/spree/""

but this does not work. I do not know which shared path I have to enter. I hope someone can help me out or provide a link with explanation.

  • How to make Ruby's Find.find follow symlinks?
  • How can I configure gem install to use “install” from the right place?
  • Rails Sub URI 403 Forbidden Errors when Deploying with Passenger for Nginx
  • How to check if a directory/file/symlink exists with one command in Ruby
  • mod_xsendfile with symbolic links
  • JRuby - Warbler does not preserve symbolic links
  • Rails Gems Symbolic Links Setup on Mac OS X
  • rvm symlink to gems for default ruby
  • One Solution collect form web for “How do I symlink my product images in production on a Capistrano deploy?”

    If you are using Capistrano 3 you can use the same method I explained in the answer to my own question here.

    In essence, :shared_children was how you’d do it in Capistrano 2, but it was removed in favor of :linked_files and :linked_dirs.

    Just create your public/spree/ directory in your repository, add it to .gitignore if you need to (it doesn’t matter if they’re tracked or not by Git), then edit your deploy.rb to use :linked_dirs:

    set :linked_dirs, %w(public/spree)

    This way, when Capistrano deploys it’ll automatically create the directory in shared/ and link it into your current release. Please keep in mind that if you need files to be present in that directory you have to copy them to shared/ manually, using a tool like rsync. The same goes for files like database.yml (for which you’d use :linked_files).

    Ruby is the best programming language in the world - Ruby on Rails.