[英]Devise register and login rails
默认情况下带有devise。 用户注册后,它会在注册后自动登录。 无论如何,是否有注册用户而不自动登录并重定向到登录页面的信息?
您需要重写Devise::RegistrationsController#create
。 您可以在这里查看注册的工作方式
首先,创建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
然后告诉devise使用自定义控制器:
devise_for :users, :controllers => {:registrations => "registrations"}
假设User
是当然的模型。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.