uninitialized constant CarrierWave

2019-05-07 14:25发布

问题:

I am deploying my first rails app using passenger and capistrano.

every thing is fine until i faced this error when I tried to launch the app in the browser.

Error message:
   uninitialized constant CarrierWave

Exception class:
   NameError

you can see the message in details at http://test.ajhezaty.com/

the site works perfectly locally and CarrierWave uploading the image correctly.

I tried to restart the VPS server by running

sudo /etc/init.d/httpd2 restart

but it didnt fix the issue.

for your information the gem installed on the server

 $ gem list | grep carrierwave
 carrierwave (0.6.1)

回答1:

You need to add carrierwave to your application.rb file like this:

require File.expand_path('../boot', __FILE__)

require 'rails/all'

require 'carrierwave'

if defined?(Bundler)
  # Bundler stuff
end

# Rest of file ommited.

This worked for me in production using nginx/unicorn. Don't forget to restart your unicorn server.



回答2:

You may have the gem installed locally, but make sure you add it to your Gemfile, bundle install through ssh, and require it in the controllers that will use it.