Unable to autoload constant API Controller in Rails 4
Rails typically only capitalizes the first name of a module. In other words, Rails expects the namespace Api::V1::GrubsController
, but you're defining it as API::V1::GrubsController
.
I had a similar issue when working on a rails 6 application.
The issue was that I defined my controller as usual
class ProductsController < ApplicationController
def index
end
Meanwhile, I had added versioning to be APIs which resulted in a namespace of this kind Api/V1
.
Here's how I solved it:
I simply had to add the namespace to the controller class definition.
class Api::V1::ProductsController < ApplicationController
def index
end
That's all.
I hope this helps
Your class name is
class API::V1::GrubsController < ApplicationController
whereas in your error its trying to look for Api::V1::GrubsController
. Change the name in your class to Api