[英]Devise register and login rails
By default with devise. 默认情况下带有devise。 After a user registers it automatically signs them in after sign up.
用户注册后,它会在注册后自动登录。 Is there anyway to register a user and not auto sign them in and redirect to the login page?
无论如何,是否有注册用户而不自动登录并重定向到登录页面的信息?
You need to override Devise::RegistrationsController#create
. 您需要重写
Devise::RegistrationsController#create
。 You can see how registration works here 您可以在这里查看注册的工作方式
First, create a custom controller subclass of Devise::RegistrationsController 首先,创建Devise :: RegistrationsController的自定义控制器子类
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
Then tell devise to use custom controller: 然后告诉devise使用自定义控制器:
devise_for :users, :controllers => {:registrations => "registrations"}
Assuming User
is the model of course. 假设
User
是当然的模型。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.