本文介绍了Rails Devise在注册后立即阻止登录,而不使用Confirmable的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用案例:
- 管理员应该能够创建用户,不应该尝试登录。
- 公共用户可以选择帐号,注册后他应该被重定向到登录页面,而不是立即签署他。
有人可以帮助我吗?
谢谢:)
推荐答案
您需要做的是覆盖Devise的RegistrationsController创建方法。
What you need to do is to override Devise's RegistrationsController create method.
有一个很好的解释,如何做到这一点。
There is an excellent explanation for how to do it here.
这是Devise创建动作:
This is Devise create action:
# POST /resource
def create
build_resource
if resource.save
if resource.active_for_authentication?
set_flash_message :notice, :signed_up if is_navigational_format?
sign_in(resource_name, resource)
respond_with resource, :location => after_sign_up_path_for(resource)
else
set_flash_message :notice, :"signed_up_but_#{resource.inactive_message}" if is_navigational_format?
expire_session_data_after_sign_in!
respond_with resource, :location => after_inactive_sign_up_path_for(resource)
end
else
clean_up_passwords resource
respond_with resource
end
end
覆盖控制器后,只需删除 sign_in(resource_name,resource)
After you override the controller, just remove sign_in(resource_name, resource)
您还可以设置方法 after_sign_up_path_for(资源)
以满足您的需要
You can also set the method after_sign_up_path_for(resource)
to fit your needs
这篇关于Rails Devise在注册后立即阻止登录,而不使用Confirmable的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!