Karim Karim - 1 year ago 76
Ruby Question

Issue finding controller concerns only in production

My application has a number of controller concerns in


When I work on this in development, everything works well. However, as soon as I push to production, I get the following error when the rails server boots up:
Uninitialized constant Concerns::MyConcern (NameError)

My concerns look like this:

module Api::V2
module Concerns
module MyConcern
extend ActiveSupport::Concern

def some_method(some_arg)
# some stuff here


I have set up
config.eager_load = true
in both my production and development environments to try and make them as consistent as possible; however, still not seeing this error occur in production.

What's strange is if I comment out the areas where I include the concerns in the controllers, the application manages to boot up; then, when I go to rails console on the production server and see if I can access Api::V2::Concerns::MyConcern I am able to access it without error. This makes me think that there's some sort of autoloading issue going on where the concerns aren't loaded when they are called in the controllers; however, I was under the impression that Rails loaded up everything in the app/ folder automatically and only areas such as the /lib had to be explicitly added.

As an FYI, my controller sits in

Any ideas what could be happening here?

Answer Source

It's highly probable that the V2 component in your path is causing the issue here. On a case insensitive file system this will be resolved as v2 which works. On a case sensitive file system it will be looking for app/controllers/api/v2/concerns/my_concern.rb which doesn't exist, and won't load.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download