2013-10-30 202 views
0

我正在使用Devise 3.1.1,並試圖在註冊後將用戶重定向到登錄頁面。 作爲Devise's wiki指示我重寫RegistrationsController下列要求:將用戶重定向到登錄頁面註冊後(登記)

class RegistrationsController < Devise::RegistrationsController 
    protected 

    def after_inactive_sign_up_path_for(resource) 
    '/users/sign_in' 
    end 
end 

按照指示,我還增加了以下行routes.rb

devise_for :users, controllers: { registrations: 'registrations'}

在這之後,我得到以下錯誤,當我轉到登錄頁面:

Invalid route name, already in use: 'new_user_session' You may have defined two routes with the same name using the:as option, or you may be overriding a route already defined by a resource with the same naming.

在我的路線我已經有這個定義:

devise_for :users, skip: :registrations 
    devise_scope :user do 
    resource :registration, 
     # disabled :edit & :destroy 
     only: [:new, :create, :update], 
     path: 'users', 
     path_names: { new: 'sign_up' }, 
     controller: 'devise/registrations', 
     as: :user_registration do 
     get :cancel 
     end 
    end 
+0

你的路線有兩個'devise_for'塊嗎? –

+0

@JonathanBender yes,'devise_for:users,skip :::registrations'和'devise_for:users,controllers:{registrations:'registrations'}'。我想我需要以某種方式將它們寫出來? – Sbbs

回答

0

只能定義一次devise_for塊,並且你已經使用默認的註冊控制器搞亂你應該能夠只是做類似的下面有設計使用你的控制器:

devise_for :users, skip: :registrations 
devise_scope :user do 
    resource :registration, 
    # disabled :edit & :destroy 
    only: [:new, :create, :update], 
    path: 'users', 
    path_names: { new: 'sign_up' }, 
    controller: 'registrations', 
    as: :user_registration do 
     get :cancel 
    end 
end 
+0

所有作品。謝謝。 – Sbbs

相關問題