默认情况下,使用devise。用户注册后,它会在注册后自动登录。有没有办法注册一个用户,而不是自动登录并重定向到登录页面?
发布于 2018-12-04 04:09:11
您需要覆盖Devise::RegistrationsController#create
。您可以查看注册是如何工作的here
首先,创建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
是模型。
https://stackoverflow.com/questions/53600596
复制相似问题