title: ActionController::RoutingError: uninitialized constant Api::V1::ApiController
body: <p>I have Rails 5 API project for controlling user tasks and I have the following error but not always for the same controller and route.</p>
  
  <pre><code>ActionController::RoutingError: uninitialized constant Api::V1::ApiController
  </code></pre>
  
  <p>I describe you a little bit my project to explain in more detail the error.</p>
  
  <p><strong>App structure</strong></p>
  
  <p><a href="https://i.stack.imgur.com/4bN5D.png" rel="noreferrer"><img src="https://i.stack.imgur.com/4bN5D.png" alt="enter image description here"></a></p>
  
  <p><strong>Routes</strong></p>
  
  <pre><code>scope module: 'api' do
    namespace :v1 do
  
      # =&gt; Login routes
      scope module: 'login' do
        match 'login', to: 'sessions#login', as: 'login', via: :post
      end
  
      # =&gt; Team routes
      scope module: 'team' do
  
        # =&gt; 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
  </code></pre>
  
  <p><strong>API Controller</strong></p>
  
  <pre><code>module Api
    class ApiController &lt; ApplicationController
  
      def respond_with_errors(object)
        render json: {errors: ErrorSerializer.serialize(object)}, status: :unprocessable_entity
      end
  
    end
  end
  </code></pre>
  
  <p><strong>Team Controller</strong></p>
  
  <pre><code>module Api::V1
    class Team::TeamController &lt; ApiController
  </code></pre>
  
  <p><strong>Tasks Controller</strong></p>
  
  <pre><code>module Api::V1
    class Team::TasksController &lt; Team::TeamController
  </code></pre>
  
  <p><strong>Login Controller</strong></p>
  
  <pre><code>module Api::V1
    class Login::LoginController &lt; ApiController
  </code></pre>
  
  <p><strong>Sessions Controller</strong></p>
  
  <pre><code>module Api::V1
    class Login::SessionsController &lt; Login::LoginController
  </code></pre>
  
  <p>When I execute login route and after tasks route, I get the error in last route and all the routes in team module. If I change the project and save it (only one blank space) and then I execute tasks route and after login route, I get the error in last route and all the routes in login module.</p>
  
  <p>It doesn't have any sense...</p>
  
  <p><strong>Rails server in this errors</strong>
  <a href="https://i.stack.imgur.com/wyh3o.png" rel="noreferrer"><img src="https://i.stack.imgur.com/wyh3o.png" alt="enter image description here"></a>
  <a href="https://i.stack.imgur.com/0HXIK.png" rel="noreferrer"><img src="https://i.stack.imgur.com/0HXIK.png" alt="enter image description here"></a></p>