One of the first things I did in my rails project after setting up model associations was setting up my model validations.
Simply put, validations exist to prevent invalid data from being saved to your database. The well on things you can do with validations is deep, but for the sake of my rails project, The Undertower, I just needed some quick and easy validations.
Originally I thought this was going to be a more difficult process than it turned out to be. Because the validations I needed were pretty simple, it went by pretty quickly. My reviews model checks for the presence of a name for the review, the review itself, and a star rating. Because the star rating turned out to be a little different than the previous two, I needed to spend some time on Google. I wound up writing it so it checks for numeric value and set parameters for how many stars someone could leave.
Outside of that my validations wound up being pretty standard: Book checks for name and title, review validations check for a name and content, and user validations check for basic login information.
Top comments (0)