Best way to load module/class from lib folder in Rails 3?

后端 未结 12 1989
别跟我提以往
别跟我提以往 2020-11-22 11:56

Since the latest Rails 3 release is not auto-loading modules and classes from lib anymore, what would be the best way to load them?

From github:

12条回答
  •  鱼传尺愫
    2020-11-22 12:30

    I had the same problem. Here is how I solved it. The solution loads the lib directory and all the subdirectories (not only the direct). Of course you can use this for all directories.

    # application.rb
    config.autoload_paths += %W(#{config.root}/lib)
    config.autoload_paths += Dir["#{config.root}/lib/**/"]
    

提交回复
热议问题