Я знаю, что в stackoverflow уже много вопросов, но ни один из них не работает в моем случае.uninitialized constant API :: V1 :: UserController
В моей routes.rb
Exer9::Application.routes.draw do
namespace :api, defaults: {format: 'json'} do
namespace :v1 do
resources :users
end
end
end
exer9/приложение/контроллеры/API/v1/users_controller.rb
module Api
module v1
class UsersController < ApplicationController
# GET /user
# GET /user.json
def index
@users = User.all
render json: @users
end
def new
end
def update
end
# GET /user/1
# GET /user/1.json
def show
@user = User.find(params[:id])
render json: @user
end
def create
@user = User.new(params[:user])
if @user.save
render json: @user
else
render json: @user.errors
end
end
def delete
end
def destroy
end
end
end
end
Update
Это мой Файл ApplicationController
class ApplicationController < ActionController::API
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
# protect_from_forgery with: :exception
end
сообщение об ошибке, что я получаю:
superclass mismatch for class UsersController
Extracted source (around line #2):
1
2
3
4
5
6
class Api::V1::UsersController < ApplicationController
# GET /user
# GET /user.json
def index
Rails.root: /home/steven/Desktop/weekly-exercises/exer9
Application Trace | Framework Trace | Full Trace
app/controllers/api/v1/users_controller.rb:2:in `<top (required)>
'
Любая помощь здесь очень ценится!
У вас есть еще один UsersController в приложение/контроллер/users_controller.rb? – Surya