auto load path rails

Step 1: Open the Rails application's configuration file, typically located at config/application.rb.

# config/application.rb

Step 2: Locate the config.autoload_paths section in the application configuration file.

config.autoload_paths += %W(#{config.root}/extras)

Step 3: Add the desired directory path to the autoload paths. This allows Rails to automatically load classes and modules from the specified directory.

config.autoload_paths += %W(#{config.root}/lib)

Step 4: Save the changes to the configuration file.

Step 5: If you want to autoload files from the lib directory, make sure that the files follow the Rails naming conventions (e.g., class names should match file names, and the file should be in the correct directory structure).

For example, if you have a file named example_class.rb in the lib directory, it should define a class named ExampleClass.

# lib/example_class.rb
class ExampleClass
  # Class implementation
end

Step 6: Ensure that the Rails application is restarted to apply the changes.

rails restart

Note: Be cautious while modifying the autoload paths, as misconfigurations may lead to unexpected behavior.