[英]Rails Controller Inheritance Routing Error
I am trying to define a namespace as admin and my routes file is the following; 我试图将一个命名空间定义为admin,而我的路由文件如下:
namespace :admin do
root 'base#index'
resources :boats
end
So I have admin folder, and inside I have base_controller.rb
; 所以我有admin文件夹,里面有
base_controller.rb
;
class Admin::BaseController < ApplicationController
before_action :logged_in_user, :auth_admin
def index
end
end
and I created cars_controller.rb inherited from BaseController; 我创建了从BaseController继承的cars_controller.rb;
class Admin::CarsController < BaseController
def index
@cars = Car.all
end
end
So, like this I get error from the console; 这样,我从控制台中得到了错误;
ActionController::RoutingError (uninitialized constant BaseController):
app/controllers/admin/cars_controller.rb:1:in `<top (required)>'
If I change instead of BaseController to ApplicationController, it works without a problem. 如果我将BaseController更改为ApplicationController,则可以正常工作。 Bur I could not figured it out why it gives such error.
Bur我不知道为什么会出现这样的错误。
ActionController::RoutingError (uninitialized constant BaseController):
ActionController :: RoutingError(未初始化的常量BaseController):
Your BaseController
is inherited from Admin
, so you need to write Admin::BaseController
instead of BaseController
您的
BaseController
继承自Admin
,因此您需要编写Admin::BaseController
而不是BaseController
class Admin::CarsController < Admin::BaseController
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.