2014-01-30 53 views
0

我有更新我的route.rb,如: -設計寶石中的路由錯誤?

devise_for :authorizes 
    devise_scope :authorizes do 
    get '/alogin' => 'devise/sessions#new' 
    get '/alogout' => 'devise/sessions#destroy' 
end 

devise_for :hrs 
    devise_scope :hrs do 
    get '/hlogin' => 'devise/sessions#new' 
    get '/hlogout' => 'devise/sessions#destroy' 
end 

devise_for :employes 
    devise_scope :employes do 
    get '/elogin' => 'devise/sessions#new' 
    get '/elogout' => 'devise/sessions#destroy' 
end 

錯誤

Could not find devise mapping for path "/alogin". This may happen for two reasons:

1) You forgot to wrap your route inside the scope block. For example: devise_scope :user do get "/some/route" => "some_devise_controller" end 
2) You are testing a Devise controller bypassing the router. If so, you can explicitly tell Devise which mapping to use: @request.env["devise.mapping"] = Devise.mappings[:user]` 

回答

1

當您使用devise_scope,你應該使用單一的模型,即:authorize(不:authorizes

只需嘗試以下代碼:

devise_for :authorizes 
    devise_scope :authorize do 
    get '/alogin' => 'devise/sessions#new' 
    get '/alogout' => 'devise/sessions#destroy' 
end 

devise_for :hrs 
    devise_scope :hr do 
    get '/hlogin' => 'devise/sessions#new' 
    get '/hlogout' => 'devise/sessions#destroy' 
end 

devise_for :employes 
    devise_scope :employe do 
    get '/elogin' => 'devise/sessions#new' 
    get '/elogout' => 'devise/sessions#destroy' 
end