2016-01-23 160 views
1

我想要定義一個名稱空間作爲管理員和我的路線文件是以下;Rails控制器繼承路由錯誤

namespace :admin do 
    root 'base#index' 
    resources :boats 
end 

所以我有管理文件夾,裏面我有base_controller.rb;

class Admin::BaseController < ApplicationController 
    before_action :logged_in_user, :auth_admin 

    def index 

    end 

end 

我創建了cars_controller.rb繼承自BaseController;

class Admin::CarsController < BaseController 

     def index 
      @cars = Car.all 
     end 

    end 

所以,像這樣我從控制檯得到錯誤;

ActionController::RoutingError (uninitialized constant BaseController): 
    app/controllers/admin/cars_controller.rb:1:in `<top (required)>' 

如果我改變而不是BaseController到ApplicationController,它的工作原理沒有問題。伯爾我無法弄清楚爲什麼會出現這樣的錯誤。

+1

似乎很直截了當;你不在模塊中,所以沒有'BaseController'。 –

回答

4

的ActionController :: RoutingError(未初始化的常量 BaseController):

BaseControllerAdmin繼承的,所以你需要寫Admin::BaseController代替BaseController

class Admin::CarsController < Admin::BaseController