Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails - why would a model inside RAILS_ROOT/lib not be available in production mode?

I have a class located inside RAILS_ROOT/lib folder, which I use in one of my helpers, and it works great in development.

When I switch to production, the application throws a NameError (uninitialized constant SomeHelper::SomeClass), and I have to load it manually in the helper:

load "#{Rails.root}/lib/some_class.rb"

module SomeHelper
  def some_method
    sc = SomeClass.new
    # blah
  end
end

I was under the impression that everything inside RAILS_ROOT/lib/* should be available all to the app - is there anything I need to configure to make this happen in prod mode? thanks.

like image 703
sa125 Avatar asked Nov 06 '22 13:11

sa125


1 Answers

When you call SomeHelper::SomeClass, Rails' autoloading mechanism will try to load file at lib/some_helper/some_class.rb

Rails won't load everything in lib/*, it will only try to load files when ConstMissing occurs.

like image 157
Vojto Avatar answered Nov 11 '22 06:11

Vojto