Rails Validate Unless Association
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?"
精彩评论