简体   繁体   English

注册(注册)后将用户重定向到登录页面

[英]Redirect user to Sign In page after Sign Up (registration)

I am using Devise 3.1.1 and am trying to redirect user to the Sign In page after he signs up. 我正在使用Devise 3.1.1,并尝试在用户注册后将用户重定向到“登录”页面。 As instructed in Devise's wiki I overridden RegistrationsController with the following: 按照Devise的Wiki中的说明,我使用以下代码覆盖了RegistrationsController:

class RegistrationsController < Devise::RegistrationsController
  protected

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

As instructed, I also added the following line to the routes.rb : 按照指示,我还将以下行添加到routes.rb

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

After which I get the following error when I go to sign in page: 之后,当我登录页面时出现以下错误:

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 :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.

In my routes I already have this defined: 在我的路线中,我已经定义了:

  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

You can only define the devise_for block once, and as you're already messing with the default registrations controller you should be able to just do something like the following to have devise use your controller: 您只能定义一次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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM