2016-09-28 2 views
2

私はAPIを開発していましたが、エンドポイントにアクセスするとUnable to autoload constant Api::V1::UsersController, expected /Users/toshikiinami/Desktop/billing/app/controllers/api/v1/users_controller.rb to define itが出てきます。Api :: V1 :: UsersController定数をオートロードできません

  • 私は適切にサブドメインのエンドポイントを設定するには、レール4.2.3

任意のアイデアを使うのか?

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 

答えて

3

問題が記載の通りである:

controllers/api/v1/users_controller.rbは、ではなく、UsersControllerクラスを定義しています。

#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

感謝を次のように

ソリューションに見えます!しかし、私は今、次のエラーがあります。 '{:locale => [:en]、:formats => [:json]、:variants => []、:ハンドラ=> [:erbでテンプレートapi/v1/users/testaaaが見つからない、:ビルダー、:raw、:ルビー、:コーヒー、:jbuilder]}。検索した: ' – Tosh

+0

@Toshi googleそれと、あなたは間違いなく良いでしょう;)今はあなたが尋ねた問題は解決されました。それを解決できない場合は、新しい質問をしてください:) –

+0

@Toshi 'render json:{テスト: 'テスト'}、ステータス::ok';) –

関連する問題