0

I have a model, User that has n, :accounts

I want to validate the presence of 2 columns (email & passwd) in the User model when that instance does not have any associated accounts. The idea being that user that signs up with Facebook does not need to use email and password.

Right now I have this, but I'm stuck

validates_presence_of :email, :passwd, :if => lambda { |u| u.accounts.length  }
jh314
  • 27,144
  • 16
  • 62
  • 82
nullfox
  • 597
  • 1
  • 4
  • 16

1 Answers1

0

Try :if => proc { |user| user.accounts.empty? }. Remember only nil and false are falsy values in ruby. Try !!0 in irb, it results in true. u.accounts.length is always true. (Also with zero length).

mbj
  • 1,042
  • 9
  • 19