更新后在rails中验证电子邮件



在我的用户模型中,我有

  validates :email, :presence=>true,   
:format   => { :with => email_regex },
:uniqueness => true

在我的控制器中,如果用户选择像这样更改它,我将更新电子邮件:

@user.update_attribute("email","#{@new_email}")

update_attribute不做验证。使用

@user.update_attributes({ :email => @new_email })

我发现update_attribute跳过验证检查,但update_attributes没有!有趣。

http://apidock.com/rails/ActiveRecord/Base/update_attributes

最新更新