Home > Enterprise >  uninitialized constant Api::Api in rails
uninitialized constant Api::Api in rails

Time:11-07

I am trying to namespace my controllers in my rails app. I have in my controller :

#controllers/api/auth_controller.rb
class Api::AuthController < ApplicationController
  def register
    
  end
end

And in my route file i have:

  namespace :api do
    get "auth/register", to: "api/auth#register"
  end

I keep on getting the error:

uninitialized constant Api::Api Object.const_get(camel_cased_word) ^^^^^^^^^^ raise MissingController.new(error.message, error.name) ^^^^^

What am i doing wrong?

CodePudding user response:

It's giving you that error because you're telling rails to look for api/ inside of namspace :api so it's trying to find Api::Api, You just need to remove the api from api/auth#register, it looks for api automatically since the route is under namespace :api, just do get "auth/register", to: "auth#register" and you should be good.

More on namespaces in routing here

  • Related