When trying to access the following URL, I get a 404 error page:
dev.mydomain.com/api
whereas my routes.rb file mentions that this route does exist:
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"}
/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)
I'm guessing the problem is that your route points to api/developers/apidoc/main
but your class is only Developers::Apidoc::MainController
. You should either not namespace that route with api
or add Api to the namespace of the controller - Api::Developers::Apidoc::MainController
.
Another important factor to keep in mind is that route namespaces need accompanying directory paths to be consistent. Getting this wrong will also cause an error like this:
Routing Error
uninitialized constant Api::Developers
In my case, I had a route structure like this:
namespace "api" do
namespace "developers" do
...
end
end
and the folder/directory structure should have been app/controllers/api/developers/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With