Rails Autoload Path

by Yuva, Co-founder

Typically autoload paths configured in application.rb will be like this:

config.autoload_paths += %W(lib)

Recently we faced a problem where we were adding another root level folder app to autoload_paths, and using one of utility classes inside that folder. Everthing worked fine in development, but not in production. We started seeing strange errors while running migrations:

cannot load such file -- app/subdir1/utility_class

Inspecting $LOAD_PATH revealed that there is no absolute path for app folder. Appending autoload_path with absolute path solved this issue.

config.autoload_paths += [ Rails.root.join("app") ]

More articles

What is TimescaleDB? A Beginner's Guide to Time-Series Data

Discover TimescaleDB, a special type of database that's great at handling time-based data like sensor readings, website traffic, or stock prices. Learn how it helps to store and analyze large amounts of time-stamped information quickly and efficiently, making it perfect for modern applications that track data over time.

Read more

Rails Inflections: The Magic Behind Singular and Plural Transformation

Learn how Rails Inflector handles singular and plural forms with customizable rules

Read more

Ready to Build Something Amazing?

Codemancers can bring your vision to life and help you achieve your goals