当我尝试加载我的api页面时,我一直得到错误“循环依赖检测,而自动加载常量API::V1::CitysController”。我搜索的所有东西似乎都表明它们可能是一个错误,但我认为没有。
我的路线:
namespace :api , defaults: {format: 'json'} do
namespace :v1 do
resources :citys
end
end我的控制器位于app/ controller /api/v1/citys_Controller.rb中。
现在里面什么都没有
class Api::V1::CitysController < ApplicationController
respond_to :json
def index
end
end不知道还有什么与这个问题有关吗?当我转到localhost:3000/api/v1/citys时,它应该只是加载一个空白页,没有任何错误。
新增路线
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"}发布于 2014-11-24 17:26:38
我不知道为什么,但是错误说它在citys_controller.rb文件中查找citys_controller.rb类,并且您有Api::V1::CitysController。因此,首先,将类的名称更改为API::V1::CitysController (注意大写的'API')。这应该能解决你眼前的问题。
https://stackoverflow.com/questions/27109505
复制相似问题