Rails console: Unable to autoload constant

dmt2989 picture dmt2989 · Apr 1, 2014 · Viewed 51.4k times · Source

I have a Customer_ratings model that allows users to leave feedback on each other. The web app is working properly, and feedback is collected, stored and displayed.

I wanted to go in and delete some feedback through the rails console, but when I enter Customer_rating.all, I get the following error:

LoadError: Unable to autoload constant Customer_rating, expected /Users/myapps/app/models/customer_rating.rb to define it

Similarly, if I enter Customer_rating[0], I get:

RuntimeError: Circular dependency detected while autoloading constant Customer_rating

I don't have this issue while accessing other tables through my console.

What could be causing the issue, and why wouldn't this error prohibit Customer_ratings from working properly through the web app?

Answer

Kirti Thorat picture Kirti Thorat · Apr 1, 2014

It seems like a case of messed up naming convention.

As per Rails naming convention, file names should be in snake_case and class names in CamelCase. In your scenario, the file name should be customer_rating.rb and class name should be CustomerRating.

After making these changes, use CustomerRating.all(as the updated class name is CustomerRating) to fetch all the customer ratings. Do not use Customer_rating.all.