From the course: Ruby on Rails 6 Essential Training: Models and Associations
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Use the multipurpose validates method - Ruby on Rails Tutorial
From the course: Ruby on Rails 6 Essential Training: Models and Associations
Use the multipurpose validates method
- Now that you know the basics of writing validations. I want to show you a slightly different way that you can write them, that sometimes it's more convenient. Here's an example of validations like we just learned in the last movie, you can see there's five different validations and all of them are on the same attribute, email. So we're going to validate its presence, its length, its uniqueness, its format, and its confirmation. This is a perfectly legitimate way for you to do it. But you may find that it's easier to write it like this. Here, I have a validates method, not validates something, right? Not validate the presence of validates length of it's just validates, the near attribute. And then I hash of the validations that I want it to run. It's a different format, but it does the same thing under the hood. When you run your validations, the validates method will go to the hash. And for every one of those keys that it…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.