I would rather not write ApplicationController in the namespace, I would suggest to follow below
Note. If you are creating a professional api, it is always useful to have Api::V1::BaseController inheritance from ActionController::Base , although I give a solution for your specific case
Ref this post: Implement a Rails API such as a professional
1) Define the application controller in the usual way in application / controllers / application_controller.rb as
class ApplicationController < ActionController::Base end
2) Define the base api controller, namely Api :: V1 :: BaseController in app / controller / api / v1 / base_controller.rb, which inherits from ApplicationController (your case), for example
class Api::V1::BaseController < ApplicationController end
3) Define your api controllers such as Api::V1::UsersController in the application / controllers / api / v1 / users_controller.rb that inherit from Api :: V1 :: BaseController
class Api::V1::UsersController < Api::V1::BaseController end
4) Add all subsequent controllers, such as Api::V1::UsersController (step 3)
Then the routing will contain the namespace routing in config / routes.rb
namespace :api do namespace :v1 do resources :users do #user routes goes here end # any new resource routing goes here # resources :new_resource do # end end end
Pramod shinde
source share