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

时间:2013-10-30 16:31:54

标签: ruby-on-rails devise

我正在使用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:为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

1 个答案:

答案 0 :(得分: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