2013-10-07 53 views
0

我有這個AdminControllerRails的路由管理錯誤

class Admin::AdminController < ApplicationController 
    before_filter :is_admin? 

    def dashboard 

    end 

    def is_admin? 
    redirect_to root_path, :flash => { :alert => "You are not an admin!" } if !current_user.admin? 
    end 

end 

,並從上面繼承此另一個控制器:

class Admin::CompetitionEntriesController < Admin::AdminController 
    before_action :set_competition_entry, only: [:show, :edit, :update, :destroy] 
.... 
end 

我的路由文件是:

Foo::Application.routes.draw do 
    root 'competition_entries#index' 

    devise_for :users 
    resources :competition_entries 

    namespace :admin do 
    root 'admin#dashboard' 
    resources :competition_entries 
    end 

.... 
.. 
. 
end 

現在爲什麼是當我嘗試達到'http://localhost:3000/admin'

時出現此錯誤
Missing template admin/admin/dashboard... 

我得到這個額外的管理員?爲什麼?我不想使用我想使用命名空間的範圍。

謝謝。

回答

0

路由不會影響模板的默認搜索路徑。如果您的控制器類名爲Foo::BarController,Rails將在app/views/foo/bar /中查找模板,除非您另行指定。

+0

你會建議'Admin :: AdminController'的另一個名字嗎? –

+0

由於'''Admin :: Admin'''對我來說看起來有點奇怪,我可能會使用像''Admin :: BaseController''' – mechanicalfish

+0

'Admin :: DashboardController#index'之類的東西,並且從Admin :: BaseController'將是我所做的事情。無論如何,就路由名稱空間而言,它直接在ruby中的模塊命名空間中進行轉換! – phoet