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
谢谢!但我现在有以下错误'缺少模板api/v1/users/testaaa {:locale => [:en],::formats => [:json],:variants => [],:handlers => [:erb ,:builder,:raw,:ruby,:coffee,:jbuilder]}。搜索:' – Tosh
@Toshi google它,你一定会很好;)现在你问的问题已经解决了。如果你不能解决它,请提出一个新的问题:) –
@Toshi尝试'渲染json:{test:'test'},status::ok';) –