Thursday, June 26, 2014

Ruby on Rails gem: Uninitialized Constant (class name)

I was working on a Ruby on Rails project earlier, and ran into a really frustrating issue regarding gems.

I added the influxdb gem to my Gemfile, did a bundle install, saw it installed successfully, then tried to use it in an ApplicationController.  No luck!  Over and over it was acting like the gem wasn't installed (Uninitialized Constant error ApplicationController::InfluxDB when trying to reference the class defined in the gem).

When I ran the same code using the rails console, it worked fine, which lead me to believe it was some problem with bundler or the environments.

It turns out the solution was simply to restart the apache/ngnix/whatever server! "service apache2 restart" in my case. Whew!

3 comments:

  1. Great to read about the question I really want to be discussed. i would follow your site.

    ReplyDelete
  2. If this really was a problem with the supplier, it's worth discussing all these problems and if it does not eliminate them then break the contract.

    ReplyDelete
  3. Sometimes one person confronting a similar problem does nothing and gives up his job while the other, spending a lot of time and effort, still finds the solution that suits everyone.

    ReplyDelete