Why does carrier wave throw a NameError: uninitialized Micropost :: PictureUploader constant?

In the Hartl Rails manual chapter 13.4.1 Loading Main Image, we add a carrier gem for loading images.

But I kept getting this error in my tests after creating the loader and adding the migration to the Microposts model:

NameError: uninitialized constant Micropost::PictureUploader

After googling, I was able to fix this by adding this to mine environments.rb

:

require 'carrierwave/orm/activerecord'

But I feel like I'm doing something wrong because Hartl doesn't, and at the end of chapter 13.4.1 it suggests that your tests should pass after a server restart.

Am I doing it wrong?

UPDATE:

After adding this line to my file, environments.rb

my tests passed. Then, once they passed, I was able to remove that line and the tests continued to pass. It's like a constant required to initialize this time.

I'll say that I forgot to run rails db:migrate

before running my tests the first time, but I kept dropping the test database, re-creating it and running migrations, restarting the server and not fixing it.

Still confused about what went wrong.

+3


source to share


3 answers


Any update on this? I faced the same problem and it was resolved by adding

requires "carrierwave / orm / activerecord"



to my environment .rb.

+3


source


BoraMa and user782220 suggested running spring stop

, then rails test

worked for me. No need to add a line require

to mine environments.rb

.

I also ran the Hartle tutorial via JetBrains RubyMine for Windows via WSL. I found that stopping the application in RubyMine doesn't actually stop the server. Every time I stopped and started the server, a different instance of Puma started up. I had to restart my entire application to get all hidden servers to stop working.



You can check if you have redundant servers running by typing ps aux | grep puma

at a command prompt.

Seems to be related to this issue

+1


source


You can try running the Uploader command again and starting your server again. Worked for me.

rails generate uploader Picture

      

0


source







All Articles