自动加载常量时检测到循环依赖 Api::V1::VersionsController
Circular dependency detected while autoloading constant Api::V1::VersionsController
我正在构建一个 rails API,当我使用适当的 url 后跟 .json
或 [= 时,我想在浏览器中查看数据14=]。我收到以下错误:
Circular dependency detected while autoloading constant Api::V1::VersionsController
我在路径music-app/app/controllers/api/v1/versions_controller.rb
中设置了一个versions_controller.rb
:
class API::V1::VersionsController < ApplicationController
respond_to :json, :xml
def index
@versions = Version.all
respond_with(@versions)
end
def show
@versions = Song.find_by(:id => params[:song_id]).versions
respond_with(@versions)
end
end
我的路线:
namespace :api do
namespace :v1 do
get '/versions' => 'versions#index'
get '/versions/:id' => 'versions#show'
end
end
我是不是遗漏了什么,如何解决?
似乎是控制器中 API 的大写导致了您的问题。
试试大写
class Api::V1::VersionsController < ApplicationController
我正在构建一个 rails API,当我使用适当的 url 后跟 .json
或 [= 时,我想在浏览器中查看数据14=]。我收到以下错误:
Circular dependency detected while autoloading constant Api::V1::VersionsController
我在路径music-app/app/controllers/api/v1/versions_controller.rb
中设置了一个versions_controller.rb
:
class API::V1::VersionsController < ApplicationController
respond_to :json, :xml
def index
@versions = Version.all
respond_with(@versions)
end
def show
@versions = Song.find_by(:id => params[:song_id]).versions
respond_with(@versions)
end
end
我的路线:
namespace :api do
namespace :v1 do
get '/versions' => 'versions#index'
get '/versions/:id' => 'versions#show'
end
end
我是不是遗漏了什么,如何解决?
似乎是控制器中 API 的大写导致了您的问题。
试试大写
class Api::V1::VersionsController < ApplicationController