[英]Redirect user to Sign In page after Sign Up (registration)
我正在使用Devise 3.1.1,並嘗試在用戶注冊后將用戶重定向到“登錄”頁面。 按照Devise的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.
Invalid route name, already in use: 'new_user_session' You may have defined two routes with the same name using the
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
您只能定義一次devise_for
塊,並且由於您已經對默認的注冊控制器感到devise_for
,因此您應該能夠執行以下類似操作來使devise使用您的控制器:
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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.