Using Carrierwave and Capistrano with Rails

Alexander Lozada

I'm having trouble getting carrierwave and capistrano to play nice with each other.

To start, I'm using this method to use both a public directory, and a private controller-handled directory for downloads. Tl;dr, carrierwave's root is actually Rails.root, and not public. However, I got around this for urls (since Rails does not use public literally in the url) by defining a base class that sets the public root, for all non-private files.

Anyways, I finally started to try and push code to production. All went well! My uploads showed just fine. However, when I pushed another deploy, I lost all of my images in the public directory.

This is a well documented case for capistrano - it only involves setting :linked_dirs. In my case, I used the following line.

set :linked_dirs,  %w{public/assets public/uploads downloads}

Where public/assets were my general css/js files, public/uploads were my multimedia files, and downloads were my protected files.

Unfortunately, this did not solve my problem. For whatever reason, all images are getting a 404 despite showing to be listed in the correct path.

Weirder still, the protected downloads folder works just fine! Perhaps this has something to do with setting the root in Carrierwave? At this point I'm tempted to just pick up paperclip for my public files, and carrierwave for private ones.

I've been at this for a good 7 hours and I still can't figure out what to do.

my deploy.rb file

my problematic image uploader file

my working product file uploader file

my nginx.conf file

sman591

Looking at the other question & answer you posted, you've set restrictive permissions on the CarrierWave upload directory and files:

# Broken permissions
CarrierWave.configure do |config|
  config.permissions = 0600
  config.directory_permissions = 0700
  config.storage = :file
end

0600 and 0700 permissions only grant access to the user that owns the file or directory. This is because both the third & fourth bits, "group" and "everyone", are set to 0.

nginx, Puma, and Capistrano probably aren't all running under the same user, which means these user-only permissions block nginx from reading the files (causing 403 errors after upload) and block Capistrano from linking the public/uploads directory (causing 404 errors after new deploys).

Instead, use more open permissions, such as what's listed on the CarrierWave README:

# Fixed permissions
CarrierWave.configure do |config|
  config.permissions = 0666
  config.directory_permissions = 0777
  config.storage = :file
end

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Generating image url using carrierwave in rails

From Dev

Using CarrierWave with Amazon Elastic Transcoder in a Rails app

From Dev

Issues displaying images in Rails using CarrierWave

From Dev

Rails nested attributes not saving using carrierwave

From Dev

/usr/bin/env ruby no such file or directory: Using capistrano 3, capistrano/rbenv, capistrano/bundler and capistrano/rails (using rails 4)

From Dev

capistrano not using rails environment with bundler properly

From Dev

deploy rails app using capistrano or aws opsworks?

From Dev

bundle error in deploying rails using capistrano

From Dev

No images and fonts production using Capistrano and Rails

From Java

Rails 4 multiple image or file upload using carrierwave

From Dev

How to get the first page of a PDF as an image using Carrierwave in rails?

From Dev

Changing the file name that we upload using carrierwave in rails

From Dev

Stream Audio from AWS to Rails App Using Fog/Carrierwave

From Dev

Rails 4: How to upload multiple images using carrierwave

From Dev

Rails 4 Multiple file upload using carrierwave and nested forms

From Dev

capistrano 3.0.1 Don't know how to build task 'starting' when using capistrano/rails/assets

From Dev

Puma Stops Running for Rails App on EC2 Instance with Nginx (using Capistrano/Capistrano Puma)

From Dev

capistrano 3.0.1 Don't know how to build task 'starting' when using capistrano/rails/assets

From Dev

Rails deployment to staging using capistrano generates the following error

From Dev

Issue with bitbucket repository to deploy rails app using capistrano

From Dev

Skip database migration while deploying Rails application using Capistrano 3

From Dev

Issue with bitbucket repository to deploy rails app using capistrano

From Dev

Deploying rails app to DigitalOcean using capistrano, nginx, puma

From Dev

Unable to deploy rails application using capistrano, bundle not found

From Dev

Rails + Mongoid + Carrierwave + Cloudinary

From Dev

Music is not playing on rails CarrierWave

From Dev

Rails: Carrierwave crop and fill

From Dev

CarrierWave on rails_admin

From Dev

Resque Capistrano Deployment in Rails

Related Related

  1. 1

    Generating image url using carrierwave in rails

  2. 2

    Using CarrierWave with Amazon Elastic Transcoder in a Rails app

  3. 3

    Issues displaying images in Rails using CarrierWave

  4. 4

    Rails nested attributes not saving using carrierwave

  5. 5

    /usr/bin/env ruby no such file or directory: Using capistrano 3, capistrano/rbenv, capistrano/bundler and capistrano/rails (using rails 4)

  6. 6

    capistrano not using rails environment with bundler properly

  7. 7

    deploy rails app using capistrano or aws opsworks?

  8. 8

    bundle error in deploying rails using capistrano

  9. 9

    No images and fonts production using Capistrano and Rails

  10. 10

    Rails 4 multiple image or file upload using carrierwave

  11. 11

    How to get the first page of a PDF as an image using Carrierwave in rails?

  12. 12

    Changing the file name that we upload using carrierwave in rails

  13. 13

    Stream Audio from AWS to Rails App Using Fog/Carrierwave

  14. 14

    Rails 4: How to upload multiple images using carrierwave

  15. 15

    Rails 4 Multiple file upload using carrierwave and nested forms

  16. 16

    capistrano 3.0.1 Don't know how to build task 'starting' when using capistrano/rails/assets

  17. 17

    Puma Stops Running for Rails App on EC2 Instance with Nginx (using Capistrano/Capistrano Puma)

  18. 18

    capistrano 3.0.1 Don't know how to build task 'starting' when using capistrano/rails/assets

  19. 19

    Rails deployment to staging using capistrano generates the following error

  20. 20

    Issue with bitbucket repository to deploy rails app using capistrano

  21. 21

    Skip database migration while deploying Rails application using Capistrano 3

  22. 22

    Issue with bitbucket repository to deploy rails app using capistrano

  23. 23

    Deploying rails app to DigitalOcean using capistrano, nginx, puma

  24. 24

    Unable to deploy rails application using capistrano, bundle not found

  25. 25

    Rails + Mongoid + Carrierwave + Cloudinary

  26. 26

    Music is not playing on rails CarrierWave

  27. 27

    Rails: Carrierwave crop and fill

  28. 28

    CarrierWave on rails_admin

  29. 29

    Resque Capistrano Deployment in Rails

HotTag

Archive