in Railscasts, Uncategorized

Railscast 041 Conditional Validations

Gist

I ask myself when would I need to use a conditional validation. I could bypass certain validations based on a specific attribute being filled or not.

A big topic of late has been female founders not applying to accelerators/incubators like YC.

If they were using a Rails app for their applications, then they could have a conditional validation on whether or not the applicant was a male or female. Each validation could have the conditional unless female? which would skip all validations except for the applicant’s contact information.

A more real example given in the episode would be to run validations on the password field. It wouldn’t be necessary to run validations if a user was just editing their name in their profile settings, but it would be necessary to run validations for the password when you are updating or creating a new record in the database.