I have a Rails app that works perfectly well locally on Mac OS X using Ruby 1.9.3 and Rails 3.2.13. This has been deployed to my Ubuntu virtual server (nginx / unicorn) using Capistrano and has been working fine.
The problem came when I installed the CarrierWave gem with RMagick. These were added to the gemfile and worked perfectly well locally, but on deploying to the server I get a 500 error every time.
A brief extract from the unicorn.log on the server:
E, [2013-06-28T12:04:05.937845 #2758] ERROR -- : reaped #<Process::Status: pid 23786 exit 1> worker=0
I, [2013-06-28T12:04:05.939517 #2758] INFO -- : worker=0 spawning...
I, [2013-06-28T12:04:05.968225 #23793] INFO -- : worker=0 spawned pid=23793
I, [2013-06-28T12:04:05.969959 #23793] INFO -- : Refreshing Gem list
E, [2013-06-28T12:04:59.669504 #23793] ERROR -- : uninitialized constant CarrierWave (NameError)
/home/deployer/apps/panto/releases/20130628115346/app/uploaders/image_uploader.rb:3:in `<top (required)>'
/home/deployer/apps/panto/releases/20130628115346/app/models/picture.rb:4:in `<class:Picture>'
/home/deployer/apps/panto/releases/20130628115346/app/models/picture.rb:1:in `<top (required)>'
The file referred to in the "uninitialized constant" error is my CarrierWave uploader class, created by CarrierWave's own generator, which begins:
# encoding: utf-8
class ImageUploader < CarrierWave::Uploader::Base
# Include RMagick or MiniMagick support:
include CarrierWave::RMagick
# include CarrierWave::MiniMagick
# Include the Sprockets helpers for Rails 3.1+ asset pipeline compatibility:
include Sprockets::Helpers::RailsHelper
include Sprockets::Helpers::IsolatedHelper
The error therefore relates to the inheritance of the main CarrierWave class.
Extract from Gemfile:
gem 'jquery-rails'
gem 'simple_form'
gem 'country_select'
gem 'carrierwave'
gem 'rmagick'
And from Gemfile.lock:
carrierwave (0.8.0)
activemodel (>= 3.2.0)
activesupport (>= 3.2.0)
...
rmagick (2.13.2)
These files are identical in my git repository and on the server. This appears to be sufficient for my locally-run app to find CarrierWave, but not for the server version.
Capistrano runs bundle:install and restarts the server on deployment, but I've tried doing both manually as well without any change.
I've seen a few similar problems reported online, but none with a solution that seems to relate to this—some say it has nothing to do with CarrierWave but don't say what it does have to do with.
Can anyone give me any pointers please while I cap deploy:rollback
again?
Thanks.
Latest update:
I have the app up and running on the server. While require 'carrierwave'
didn't work in the application.rb file, logging into the server as the deploy user, navigating into the app directory, opening a rails console using RAILS_ENV=production bundle exec rails c
and then typing require 'carrierwave'
seems to have made it work.
I'm not marking this as answered just yet as I suspect it may all stop again at the next deploy, but it perhaps narrows down the problem.