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.

Overview of validation methods

Overview of validation methods - Ruby on Rails Tutorial

From the course: Ruby on Rails 6 Essential Training: Models and Associations

Start my 1-month free trial

Overview of validation methods

- [Instructor] In this chapter, we're going to be learning about validations, and we're going to start by getting an overview. Validations allow us to make sure that data meets a set of requirements before it's saved to the database. You can think of them as rules that our data must follow. Like we talked about it in the last chapter, it makes sense for us to put this kind of business logic in our models. We certainly could check that data meets our requirements, in the view, we could use JavaScript to make sure that the form data was good or we could wait until those form parameters were submitted to the controller, and we could check it there. But it makes more sense to make our models smarter by telling them about what should be considered valid data in the database or not. And that way, regardless of where we're submitting data from the application, from whatever form or controller it may be, it'll still follow our…

Contents