Rails production - all pictures are broken after new deploy

Ok, I found the solution. The problem appeared because I didn't change the default folder to keep images. You can find your default folder in public/uploads. That means that each cap deploy will create a new empty folder which doesn't contain your older files.

To fix this you should create another folder which doesn't live in your application. I choose the easiest way. I created symlinlk.

My steps:

1) On your server go to your app's shared folder (it generated automatically via capistrano). And then create your folder to keep new images:

$ mkdir uploads

2) Give necessary rights for a created folder:

$ sudo chmod 775 uploads

3) On your local machine in config/deploy.rb add:

task :symlink_config, roles: :app do
  ...
  run "ln -nfs #{shared_path}/uploads #{release_path}/public/uploads"
end

4) Then push git and deploy:

$ git push
$ cap deploy:symlink
$ cap deploy

Now everything works fine.


Good one! I've extended your capistrano recipe.

# config/recipes/carrierwave.rb

namespace :carrierwave do 
  task :uploads_folder do
    run "mkdir -p #{shared_path}/uploads"
    run "#{sudo} chmod 775 #{shared_path}/uploads"
  end
  after 'deploy:setup', 'carrierwave:uploads_folder'

  task :symlink do 
    run "ln -nfs #{shared_path}/uploads #{release_path}/public/uploads"
  end
  after 'deploy', 'carrierwave:symlink'
end