2016-09-28 3 views
2

Ich konnte API entwickeln, aber wenn ich auf den Endpunkt zugreifen Unable to autoload constant Api::V1::UsersController, expected /Users/toshikiinami/Desktop/billing/app/controllers/api/v1/users_controller.rb to define it kommt heraus.Kontinuierliche Apo :: V1 :: UsersController

  • Ich benutze Schienen 4.2.3

Irgendwelche Ideen richtig den Sub-Domain-Endpunkt zu konfigurieren?

config/routes.rb

Rails.application.routes.draw do  
    namespace :api, defaults: { format: :json }, constraints: { subdomain: 'api' }, path: '/' do 
    scope module: :v1 do 
     resources :users, only: [:index] 
    end 
    end 
end 

controllers/api/v1/users_controller.rb

class UsersController < ActionController::Base 
    def index 
    render 'test' => 'json' 
    end 
end 

/etc/hosts

## 
# Host Database 
# 
# localhost is used to configure the loopback interface 
# when the system is booting. Do not change this entry. 
## 
127.0.0.1 localhost 
127.0.0.1 api.localhost.local 

Antwort

3

Das Problem ist, wie gesagt:

controllers/api/v1/users_controller.rb definiert UsersController Klasse, nicht Api::V1::UsersController.

Die Lösung sieht wie folgt aus:

#controllers/api/v1/users_controller.rb 
module Api 
    module V1 
    class UsersController < ActionController::Base 
     def index 
     render json: { test: 'test' }, status: :ok 
     end 
    end 
    end 
end 
+0

Dank! aber ich habe folgenden Fehler jetzt 'Fehlende Vorlage api/v1/Benutzer/testaaa mit {: locale => [: en],: formats => [: json],: variants => [],: handlers => [: erb ,: Erbauer,: roh,: Rubin,: Kaffee,: jbuilder]}. Gesucht in: ' – Tosh

+0

@ Toshi Google es und du wirst sicher gut sein;) für jetzt ist das Problem, das Sie gefragt haben, gelöst. Wenn Sie es nicht lösen können, stellen Sie eine neue Frage :) –

+0

@ Toshi versuchen 'render json: {test: 'test'}, status:: ok';) –