2010-12-09 105 views
3

我正在使用Devise,一切都一直很好,但我是現在試圖將東西移動到「管理員」名稱空間中。Devise in namespace - ActionController :: RoutingError(沒有路由匹配{:action =>「new」,:controller =>「devise/sessions」})

我有一個看起來像一個路線:

namespace :admin do 
    devise_for :users, :controllers => { :registrations => "admin/users/registrations" } 
end 

在我的控制器之一,我有

before_filter :authenticate_user! 

但時調用它拋出:

ActionController::RoutingError (No route matches {:action=>"new", :controller=>"devise/sessions"}): 

任何想法?

+1

您的RegistrationsController的外觀如何? – 2010-12-10 03:46:08

回答

1

我這樣做:

scope '/admin' do 
    devise_for :admins 
end 
0

對此的解決辦法是使用path選項和移動devise_fornamespace塊外

devise_for :users, :path => '/admin', 
        :controllers => { :registrations => "admin/users/registrations" } 
namespace :admin do 
    # other resource controllers 
end 

也許它不是優雅(或直覺),但它適用於我!

3

按照該設計文檔(其中,因爲這可能會發布已經改變),你可以使用以下說明:

# ... 
#  
# Notice that whenever you use namespace in the router DSL, it automatically sets the module. 
# So the following setup: 
# 
#  namespace :publisher do 
#  devise_for :account 
#  end 
# 
# Will use publisher/sessions controller instead of devise/sessions controller. You can revert 
# this by providing the :module option to devise_for. 
#  
# ... 

希望這可以幫助別人。

相關問題