Capistrano Deleting Paperclip Images

烂漫一生 提交于 2019-12-11 12:07:13

问题


For some reason Capistrano deletes all the images in my database every time I cap all the images get removed from all the users. Typically what I have done is have to refill the databased with the same images that had been delete by capistrano. I've attached my deploy.rb file, can someone give me some insight.

require "bundler/capistrano"
set :rvm_ruby_string, '1.9.3p429'
set :rvm_type, :user
set :user, ""
set :password, ""
set :domain, ""
set :applicationdir, ""

set :scm, :git
set :repository,  ""
set :git_enable_submodules, 1 # if you have vendored rails
set :branch, "release"
set :rails_env, 'production'

#set :git_shallow_clone, 1
set :scm_verbose, true

# roles (servers)
role :web, domain
role :app, domain
role :db,  domain, :primary => true
set :port, 22


# deploy config
set :deploy_to, applicationdir
set :deploy_via, :remote_cache

# additional settings
default_run_options[:pty] = true  # Forgo errors when deploying from windows
ssh_options[:forward_agent] = true

#ssh_options[:keys] = %w(/home/user/.ssh/id_rsa)            # If you are using ssh_keysset :chmod755, "app config db lib public vendor script script/* public/disp*"set :use_sudo, false

# runtime dependencies
depend :remote, :gem, "bundler", ">=1.0.0.rc.2"


# tasks
namespace :deploy do
  task :start, :roles => :app do
    run "touch #{current_path}/tmp/restart.txt"
  end

  task :stop, :roles => :app do
    # Do nothing.
  end

  desc "Restart Application"
  task :restart, :roles => :app do
    run "touch #{current_path}/tmp/restart.txt"
  end

  desc "Symlink shared resources on each release"
  task :symlink_shared, :roles => :app do
    #run "ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml"
  end
end



after 'deploy:update_code', 'deploy:symlink_shared'

namespace :bundler do
  desc "Symlink bundled gems on each release"
  task :symlink_bundled_gems, :roles => :app do
    run "mkdir -p #{shared_path}/bundled_gems"
    run "ln -nfs #{shared_path}/bundled_gems #{release_path}/vendor/bundle"
  end

  desc "Install for production"
  task :install, :roles => :app do
    run "cd #{release_path} && bundle install --without development test"
  end

end

after 'deploy:update_code', 'bundler:symlink_bundled_gems'
after 'deploy:update_code', 'bundler:install'

回答1:


2 years later, same trouble...

Here's my fix. In your deploy.rb :

# Default value for linked_dirs is []
# set :linked_dirs, fetch(:linked_dirs, []).push('bin', 'log', 'tmp/pids', 'tmp/cache', 'tmp/sockets', 'vendor/bundle', 'public/system')
set :linked_dirs, fetch(:linked_dirs, []).push('public/system')

This will store your images in yourapp/shared/system (instead of yourapp/current/system) and create symlinks on each deploy.

Source : https://github.com/capistrano/rails/issues/104#issuecomment-72766586




回答2:


More than likely your public/images (or wherever Paperclip stores images) is not a shared symlink, and thus when Capistrano links a new release, the images are not copied.

There's documentation about this right in the Paperclip README file, covering how not to fall into this trap.



来源:https://stackoverflow.com/questions/19807428/capistrano-deleting-paperclip-images

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!