Rails: NameError: uninitialized constant Article::ImageUploader when using Carrierwave on rails 4.1.5

Didin Ahmadi picture Didin Ahmadi · Sep 7, 2014 · Viewed 25.8k times · Source

I'm learning rails 4.1.5

I got this error:

2.1.1 :008 > Article
NameError: uninitialized constant Article::ImageUploader
    from /Volumes/disk0s4/www/rails/blog/app/models/article.rb:4:in `<class:Article>'
    from /Volumes/disk0s4/www/rails/blog/app/models/article.rb:1:in `<top (required)>'
    from (irb):8
    from /Users/didin/.rvm/gems/ruby-2.1.1/gems/railties-4.1.5/lib/rails/commands/console.rb:90:in `start'
    from /Users/didin/.rvm/gems/ruby-2.1.1/gems/railties-4.1.5/lib/rails/commands/console.rb:9:in `start'
    from /Users/didin/.rvm/gems/ruby-2.1.1/gems/railties-4.1.5/lib/rails/commands/commands_tasks.rb:69:in `console'
    from /Users/didin/.rvm/gems/ruby-2.1.1/gems/railties-4.1.5/lib/rails/commands/commands_tasks.rb:40:in `run_command!'
    from /Users/didin/.rvm/gems/ruby-2.1.1/gems/railties-4.1.5/lib/rails/commands.rb:17:in `<top (required)>'
    from /Volumes/disk0s4/www/rails/blog/bin/rails:8:in `<top (required)>'
    from /Users/didin/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
    from /Users/didin/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
    from -e:1:in `<main>'

my file: article.rb

class Article < ActiveRecord::Base    
    validates_presence_of :title, :body
    belongs_to :user
    mount_uploader :image, ImageUploader
end

I got error when running rails console

when I write a word 'Article' on the console, it raises error above, but it working fine when this line mount_uploader :image, ImageUploader at article.rb's file removed.

when that line is restored, the error comes again. so it seems the error is caused that line, but I'm not sure.

anyone can fix this, please...

thank you for reading and answer :-)

Answer

Max Rogers picture Max Rogers · Jan 15, 2015

I know this is a few months late but I stumbled across this issue myself. My solution was to paste

require 'carrierwave/orm/activerecord'

into the config/environment.rb file. Just append it at the end.

My Env: Ruby 2.1.2p95 ; Rails 4.1.7 ; Carrierwave-0.10.0