[英]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.