ActionController :: RoutingError: uninitialized constant Api :: V1 :: ApiController

I have a Rails 5 API project for managing user tasks, and I have the following error, but not always for the same controller and route.

ActionController::RoutingError: uninitialized constant Api::V1::ApiController

I will tell you a little about my project to explain the error in more detail.

Application structure

enter image description here

Routes

scope module: 'api' do
  namespace :v1 do

    # => Login routes
    scope module: 'login' do
      match 'login', to: 'sessions#login', as: 'login', via: :post
    end

    # => Team routes
    scope module: 'team' do

      # => no admin routes
      resources :tasks, except: [:index] do
        collection do
          match ':view', to: 'tasks#index', as: 'tasks', via: [:get, :post]
        end
      end
    end

  end
end

API controller

module Api
  class ApiController < ApplicationController

    def respond_with_errors(object)
      render json: {errors: ErrorSerializer.serialize(object)}, status: :unprocessable_entity
    end

  end
end

Command controller

module Api::V1
  class Team::TeamController < ApiController

Task controller

module Api::V1
  class Team::TasksController < Team::TeamController

Input controller

module Api::V1
  class Login::LoginController < ApiController

Session Controller

module Api::V1
  class Login::SessionsController < Login::LoginController

When I perform the login and the task route, I get an error message on the last route and all the routes in the command module. If I change the project and save it (only one empty space), and then complete the task route and after login, I get an error message on the last route and all routes in the input module.

It makes no sense ...

enter image description here enter image description here

+4
2

- ::Api::ApiController:

module Api::V1
  class Team::TeamController < ::Api::ApiController

Api::V1::ApiController, Api::ApiController

+3

Api::ApiController.
app/controllers/api/v1/api_controller.rb V1

module Api::V1
  class ApiController < ApplicationController
    ..
  end
end

UPDATE

ApiController V1,

module Api::V1
  class Team::TeamController < ::Api::ApiController
+3

Source: https://habr.com/ru/post/1657729/


All Articles