首页 > 解决方案 > 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!

我正处于在这里黑暗中拍摄的地步。有人知道我当时缺少什么吗?

标签: ruby-on-railsrubyherokuruby-on-rails-5.1

解决方案


推荐阅读