尝试访问以下URL时,出现 404错误页面:



而我的routes.rb文件提到此路由确实存在:

routes.rb

constraints :subdomain => 'dev' do
  root :to => 'developers/main#index', :as => :developers
  namespace 'api', :as => :developers_api do
    root :to => 'developers/apidoc/main#index'
  end
end

耙路
         developers   /(.:format)      {:subdomain=>"dev", :controller=>"developers/main", :action=>"index"}
developers_api_root   /api(.:format)   {:subdomain=>"dev", :controller=>"api/developers/apidoc/main", :action=>"index"}

Controller

/app/controllers/developers/apidoc/main_controller.rb
class Developers::Apidoc::MainController < Developers::BaseController
  def index
  end
end

日志
[router]: GET dev.mydomain.com/api dyno=web.1 queue=0 wait=0ms service=14ms status=404 bytes=0
[web.1]: Started GET "/api"
[web.1]: ActionController::RoutingError (uninitialized constant Api::Developers)

最佳答案

我猜测问题是您的路线指向api/developers/apidoc/main,但您的类(class)只是Developers::Apidoc::MainController。您要么不应该使用api进行路由的 namespace ,要么不应该将Api添加到 Controller 的 namespace -Api::Developers::Apidoc::MainController

10-07 15:48