From the course: Ruby on Rails 5 Essential Training

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Validates method

Validates method - Ruby on Rails Tutorial

From the course: Ruby on Rails 5 Essential Training

Start my 1-month free trial

Validates method

- [Narrator] Now that we've taken a look at the validation methods, I want to show you another style for writing them. This is essentially a shortcut for the validation methods that we just saw. You'll sometimes here the shortcut style referred to as sexy validations. To see what they are, let's first take a look at a regular validation. Here we can see that we have five different validation methods for email: for validating it's presence, it's length, it's uniqueness, it's format, and it's confirmation. The validates method wraps up all of these validations on email into one method call like this. Now instead of validates presence of email, I just have validates email and then a hash telling it what validations I want to use. So I have one for presence, one for length, one for uniqueness, one for format, and one for confirmation. And each one of those accepts a value along with it, and that value is the set of options that we want to pass in for each one. So guess what it does for…

Contents