Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Loading module/class from lib folder in Rails 3

    • 0
    • 2
    • 2
    • 0
    • 0
    • 0
    • 0
    • 0
    • 331
    Comment on it

    Autoloading of modules/classes from lib directory is no more supported by Rails 3. There has been number of if and buts in its support and against but unfortunately it has been removed. While lazy loading was a very good feature where developer need not to keep track of each and every file/folder he needs to manually include.

    Fortunately there is a way of enabling autoloading again in Rails 3 . While most of the solution on net only show how to include particular file/folder we can do it for entire lib folder by making following changes in config/application.rb:

    #application.rb
    
    # Custom directories with classes and modules you want to be autoloadable.
    # config.autoload_paths += %W(#{config.root}/extras)
    config.autoload_paths += %W(#{config.root}/lib)
    config.autoload_paths += Dir["#{config.root}/lib/**/"] 
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: