首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >设计注册和登录rails

设计注册和登录rails
EN

Stack Overflow用户
提问于 2018-12-04 03:30:08
回答 1查看 83关注 0票数 0

默认情况下,使用devise。用户注册后,它会在注册后自动登录。有没有办法注册一个用户,而不是自动登录并重定向到登录页面?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-12-04 04:09:11

您需要覆盖Devise::RegistrationsController#create。您可以查看注册是如何工作的here

首先,创建Devise::RegistrationsController的自定义控制器子类

代码语言:javascript
复制
class RegistrationController < Devise::RegistrationsController
  def create
    build_resource(sign_up_params)

    resource.save
    yield resource if block_given?
    if resource.persisted?
      if resource.active_for_authentication?
        set_flash_message! :notice, :signed_up
        respond_with resource, location: root_path # Change this to whatever route your want
      else
        set_flash_message! :notice, :"signed_up_but_#{resource.inactive_message}"
        expire_data_after_sign_in!
        respond_with resource, location: after_inactive_sign_up_path_for(resource)
      end
    else
      clean_up_passwords resource
      set_minimum_password_length
      respond_with resource
    end
  end 
end

然后告诉devise使用自定义控制器:

devise_for :users, :controllers => {:registrations => "registrations"}

当然,假设User是模型。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53600596

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档