开发者

Rails Validate Unless Association

开发者 https://www.devze.com 2023-04-12 04:41 出处:网络
Just wondering what the best call it use when validating unless an object has an association. For example: I want to validate a user\'s email and password unless it has one authe开发者_StackOverflownt

Just wondering what the best call it use when validating unless an object has an association. For example: I want to validate a user's email and password unless it has one authe开发者_StackOverflowntication (OAuth). I tried using:

# user.rb
has_many :authentications
validates_presence_of :email, :unless => "authentications.exists?"
validates_presence_of :password, :unless => "authentications.exists?"

Which worked fine for 'updates' but not 'creates'.


Try validates_presence_of :email, :unless => "authentications.present?"

0

精彩评论

暂无评论...
验证码 换一张
取 消