Class User attr_accessor :password validates :password, :presence => true, :on => create validates :password, :length => { :minimum => 6 :maximum => 8 }, :if => :password? . . . endWhen calling valid? on the User object I got a method undefined error for password?. I could't quite figure it out and I was wondering what I was doing wrong until eventually I tried appending the following to the bottom of the class definition:
. . . def password? self.password.present? end . . .An seemingly simple and obvious solution, I know, but this took me about an hour to figure out after Stack Overflow failed me for the first time.
I hope this helps save someone else the frustration I endured.
No comments:
Post a Comment