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

后端 未结 12 1982
别跟我提以往
别跟我提以往 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:32

    In my case I was trying to simply load a file directly under the lib dir.

    Within application.rb...

    require '/lib/this_file.rb' 
    

    wasn't working, even in console and then when I tried

    require './lib/this_file.rb' 
    

    and rails loads the file perfectly.

    I'm still pretty noob and I'm not sure why this works but it works. If someone would like to explain it to me I'd appreciate it :D I hope this helps someone either way.

提交回复
热议问题