Peter Ryder
Peter Ryder

Reputation: 21

Rails autoloads lib classes and modules in staging but not when pushed to production

I recently upgraded my rails app from Thin to Puma, hosted on Heroku. Everything works perfectly on staging environment, but when I deploy to production no modules or classes seem to be loaded.

The app launches and run on production but whenever one of the classes in my /lib directory is needed I get a NameError (uninitialized constant) error.

In my application.rb file this is where I load the lib files:

config.autoload_paths += Dir["#{config.root}/lib", "#{config.root}/lib/**/"]

Running Rails 3.1.1 and Ruby 2.1.1

I can't work out why they would load in staging but not production. Any help would be much appreciated!

Upvotes: 2

Views: 201

Answers (2)

Cuong Nguyen
Cuong Nguyen

Reputation: 29

You should try add those line to application.rb:

config.eager_load_paths << Rails.root.join('lib')
config.autoload_paths << Rails.root.join('lib')

It worked for me

Upvotes: 1

Thomas R. Koll
Thomas R. Koll

Reputation: 3139

Try Rails.root instead of config.root.

Upvotes: 1

Related Questions