Adding lib to 'config.autoload_paths' in Rails 3 does not autoload my module

后端 未结 6 1993
抹茶落季
抹茶落季 2020-11-28 02:52

I place a file name g.rb in side Rails.root/lib folder The file content is like this:

module Google
end

Then I add

         


        
6条回答
  •  清酒与你
    2020-11-28 03:46

    I had a similar problem with getting my module to run on Heroku. In addition to the autoload naming convention stated by Stephen C, I found out that the module code must be require'd due to a threadsafe assumption made by the Rails' production environment on Heroku (even though threadsafe was commented out in my production.rb configuration file.) As soon as I require'd the module file before calling include on the module, everything started to work.

    require 'mymodule'
    include Mymodule
    

    Please take a look at this excellent article on the subject of getting Modules to load correctly in Heroku (production).

提交回复
热议问题