简体   繁体   English

如何在Rails中修改devise gem的默认行为

[英]How to modify the default behaviour of devise gem in Rails

Devise by default runs resource.save in RegistrationsController#create and not resource.save! 默认情况下,Devise在RegistrationsController#create运行resource.save ,而不是resource.save! . That makes not to raise my resource validations errors. 这不会引起我的资源验证错误。 I'm sure they have had thought about this. 我相信他们已经考虑过了。 I took out :validatable from the resource model but it doesn't help. 我从资源模型中取出了:validatable ,但是它没有帮助。

My question is: doesn't Devise give an option for this? 我的问题是:Devise不为此提供选择吗?

resource.save! will cause a nasty 500 error if your user model is in an invalid state, whereas resource.save will add the validation errors to the user.errors hash and return false so that the validation errors can be displayed and corrected. 如果您的用户模型处于无效状态,将导致讨厌的500错误,而resource.save会将验证错误添加到user.errors哈希并返回false,以便可以显示和更正验证错误。

I am therefore not sure why you could prefer save! 因此,我不确定您为什么更喜欢save! ?? ??

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM