Stop deleting your files/images when you deploy!

This is one of those ‘Duh!’ moments we all have after the fact…When using something like the ‘file_column’ plugin for Rails, the default will upload your images to the RAILS_ROOT/public directory which is, of course, in Subversion. So it gets blown away when you ‘cap_deploy’ because you didn’t sync all the files that your users have uploaded to your local machine and commit to Subversion (which you wouldn’t do anyway since their images shouldn’t be in your repository…)Anyway, here’s how to get around it.

  1. SSH into your server and make a new ‘uploads’ directory under the ‘#{application}/shared/system’ folder:
    mkdir /path/to/your/railsapp/shared/system/uploads
  2. chmod it to 775:
    chmod 755 /path/to/your/railsapp/shared/system/uploads
  3. Edit your ‘RAILS_ROOT/config/deploy.rb’ file and add the following line INSIDE the ‘task :after_update_code do’ block:
    run "ln -s /path/to/your/#{application}/shared/system/uploads #{release_path}/public/uploads"
  4. (optional) If you are using ‘file_column’ plugin, change line 596 of ‘RAILS_ROOT/vendor/plugins/file_column/lib/filecolumn.rb’ to:
    :root_path => File.join(RAILS_ROOT, "public/uploads"),

    and change line 80 of ‘RAILS_ROOT/vendor/plugins/file_column/lib/file_column_helper.rb’ to:

    url << "/uploads/"
  5. ‘cap_deploy’ and you should be good to go!

No Comments

Post a comment