Loading custom libs from /lib folder #4328

Closed
daniel2d2art opened this Issue Jan 5, 2012 · 3 comments

2 participants

@daniel2d2art

I've my custom libs on /lib folder, but can't automate the loading. I need to require by hand on each code file is need :(
I use /lib/ to implement core and custom classes.

I implement y libs in this way:

  • In "/lib/" folder
    /lib/my_custom.rb
    /lib/my_custom_lib/
    /lib/my_custom_lib/custom.rb
    /lib/my_custom_lib/string.rb

  • "/lib/my_custom.rb" file has this code:
    require "#{File.dirname(FILE)}#{'/my_custom_lib/custom'}"
    require "#{File.dirname(FILE)}#{'/my_custom_lib/string'}"

  • In "/config/application.rb" file has this code:
    config.autoload_paths += %W(#{config.root}/lib)
    config.autoload_paths += %W(#{config.root}/lib/**/)

But String class is not exentded with string.rb file, and custom.rb implementantions are not visible from code unless hand required for each code file that uses it.

what's wrong????? (Using RoR 3.1.3)

@josevalim
Ruby on Rails member

Please don't use the issues tracker for questions. Use stack overflow, mailing list, etc...

@josevalim josevalim closed this Jan 5, 2012
@daniel2d2art

This not a question. I'm solving this handling requiring the lib. It seem like issue.

"config.autoload_paths += %W(#{config.root}/lib) it /config/application.rb is not loading the lib folder in rails 3.1.3."
More details about issue:

Implemented in this way:

In "/lib/" folder
/lib/my_custom.rb
/lib/my_custom_lib/
/lib/my_custom_lib/custom.rb
/lib/my_custom_lib/string.rb

"/lib/my_custom.rb" file has this code:
require "#{File.dirname(FILE)}#{'/my_custom_lib/custom'}"
require "#{File.dirname(FILE)}#{'/my_custom_lib/string'}"

In "/config/application.rb" file has this code:
config.autoload_paths += %W(#{config.root}/lib)
config.autoload_paths += %W(#{config.root}/lib/**/)

using RoR 3.1.3

best

@daniel2d2art

reopen comment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment