ruby-on-rails - ActionController::RoutingError(未初始化的常量 ApplicationController):
问题描述
我正在尝试升级我的 rails 应用程序。我以前从未这样做过,但在了解了 5.1 中的一项最新功能(我使用的是 5.0.7)后,我决定最好这样做。我认为我的最终目标是一直到最新,因为我意识到从长远来看这是一个好主意。
进行更改后我坚持的一件事是,我遇到了路由错误。
我得到的服务器错误是
ActionController::RoutingError (uninitialized constant Downtown::ApplicationController):
当我将它部署到 heroku 时(以为在我这样做之前已经设置好了),我得到的错误是
! Unable to load application: NameError: uninitialized constant Downtown::ApplicationController
bundler: failed to load command: puma (/app/vendor/bundle/ruby/2.5.0/bin/puma)
NameError: uninitialized constant Downtown::ApplicationController
/app/app/controllers/properties_controller.rb:1:in `<top (required)>'
在此切换之前,我的路由中的一件事是我有一些嵌套路由。然而,查看发行说明 ,我没有发现任何需要在我的路由文件中进行更改的内容,并且发行说明中唯一相关的是Direct & resolved
我认为我没有使用的路由。
我的路线是
resources :downtowns do
resources :properties do
end
end
我的应用程序控制器基本上是空的。
class ApplicationController < ActionController::Base
protect_from_forgery with: :exception
end
我的市区控制器是
class DowntownsController < ApplicationController
before_action :find_downtown, only: [:show, :edit, :update, :destroy]
before_action :authenticate_user!, except: [:index, :show]
....the general def show and create files and such....
end
我的属性控制器是
class PropertiesController < Downtown::ApplicationController
before_action :find_property, only: [:show, :edit, :update, :destroy]
before_action :authenticate_user!, except: [:index, :show]
....the general def show and create files and such....
end
我的两个模型都通往ApplicationRecord
class Downtown < ApplicationRecord
end
class Property < ApplicationRecord
end
我的申请记录如下。我把它设置为ActiveRecord::Base
我认为是正确的?
class ApplicationRecord < ActiveRecord::Base
self.abstract_class = true
end
我的app/config/environment.rb
文件initialize!
在线失败。
# Load the Rails application.
require_relative 'application'
# Initialize the Rails application.
Rails.application.initialize!
我正处于在这里黑暗中拍摄的地步。有人知道我当时缺少什么吗?
解决方案
推荐阅读
- html - 响应式 SVG 填充形状
- python - Scrapy:合并来自不同站点的项目
- php - 根据另一个数组的内容过滤多维数组的内容
- verilog - 为什么大多数verilog代码在posedge时钟中工作?
- vue.js - 即使对于单个开发人员,道具定义也应该尽可能详细吗?
- android - 使 Exoplayer 隐藏式字幕 (CEA-608) 出现在底部
- matlab-deployment - 来自 Matlab 的函数,从 Matlab Library Compiler 编译为 Python 包,是否加密?
- javascript - 从 Chrome 扩展程序中删除 localStorage
- python - 使用函数调用填充熊猫数据框中的列
- port - HAProxy 将前端绑定到单个 IP 上的多个端口