Reputation: 442
I keep getting the error "Circular dependency detected while autoloading constant API::V1::CitysController" when I try load my api page. Everything I've searched seems to suggest their might be a typo but I don't think there is one.
My routes:
namespace :api , defaults: {format: 'json'} do
namespace :v1 do
resources :citys
end
end
my controller is in app/controllers/api/v1/citys_controller.rb
Theres nothing in it really at the moment
class Api::V1::CitysController < ApplicationController
respond_to :json
def index
end
end
Not sure what else is relevant to the problem? It should just load a blank page without any errors when I go to localhost:3000/api/v1/citys
Added routes
Prefix Verb URI Pattern Controller#Action
pages_home GET /pages/home(.:format) pages#home
root GET / pages#home
api_v1_citys GET /api/v1/citys(.:format) api/v1/citys#index {:format=>"json"}
POST /api/v1/citys(.:format) api/v1/citys#create {:format=>"json"}
new_api_v1_city GET /api/v1/citys/new(.:format) api/v1/citys#new {:format=>"json"}
edit_api_v1_city GET /api/v1/citys/:id/edit(.:format) api/v1/citys#edit {:format=>"json"}
api_v1_city GET /api/v1/citys/:id(.:format) api/v1/citys#show {:format=>"json"}
PATCH /api/v1/citys/:id(.:format) api/v1/citys#update {:format=>"json"}
PUT /api/v1/citys/:id(.:format) api/v1/citys#update {:format=>"json"}
DELETE /api/v1/citys/:id(.:format) api/v1/citys#destroy {:format=>"json"}
Upvotes: 2
Views: 736
Reputation: 8846
I'm not sure why, but the error says it is looking for API::V1::CitysController
class in your citys_controller.rb
file and you have Api::V1::CitysController
. So first and foremost change the name of your class to API::V1::CitysController
(note the capitalized 'API'). That should solve your immediate problem.
Upvotes: 1