开发者

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?"

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜