简体   繁体   English

无法在API控制器中自动加载常量

[英]Unable to autoload constant in API Controller

I'm trying to setup a RoR API but I'm hitting a few roadbump along the way. 我正在尝试设置RoR API,但在此过程中遇到了一些麻烦。 After tiresome coding to get the database setup right I'm hitting an error that doesn't quite make sense to me (I'm new to RoR) 经过繁琐的编码以正确设置数据库后,我遇到了一个对我来说没有意义的错误(我是RoR的新手)

Unable to autoload constant Api::V1::SubmissionsController, expected ./app/controllers/api/v1/submissions_controller.rb to define it

I'm not quite sure what this error means and my interwebs searches are coming up empty on a clear answer. 我不太确定这个错误是什么意思,我的互联网搜索在一个明确的答案上空了。 I'm hoping any of you can help me here. 我希望任何人都可以在这里为我提供帮助。

Routes 路线

Rails.application.routes.draw do
 namespace :api, :defaults => {:format => :json} do
   namespace :v1 do
     get "/submissions", to: "submissions#index"
   end
 end
end

submission.rb submission.rb

class Submission < ActiveRecord::Base

end

submissions_controller.rb submissions_controller.rb

class API::V1::SubmissionsController < ApplicationController
  def index
   @submissions = Submission.all
   render json: @submissions, status: :ok
  end
end

Your file contains: 您的文件包含:

class API::V1::SubmissionsController < ApplicationController

Rails expects: Rails期望:

class Api::V1::SubmissionsController < ApplicationController

What does your folder structure look like for app/controllers & app/views? 应用程序/控制器和应用程序/视图的文件夹结构是什么样的? Depending on how these files were generated, by "rails generate" or manually created, if you namespace, the folder structure has to match in controllers and views directories. 根据这些文件的生成方式(通过“ rails生成”还是手动创建),如果使用名称空间,则文件夹结构必须在控制器和视图目录中匹配。

app/controllers/api/v1 app/views/api/v1 app / controllers / api / v1 app / views / api / v1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM