Understanding Ruby on Rails ActiveRecord Validations
Web-Crunch
Hi, My name is Andy Leverenz and I work as a Product Designer at Dribbble. For fun, I design, code, and write. Check out my blog called Web-Crunch https://web-crunch.com where I publish design and development tutorials with the occasional vlog.
====================
Data is a great thing but the wrong data can be very very bad. Luckily, if you're a Ruby on Rails programmer you have a nice API of ActiveRecord validation helpers at your disposal.
This guide is an exploration of common and not so common ActiveRecord validations in a given Ruby on Rails application. Use it to help keep your databases happy!
Why use validations?
To ensure only valid data is saved to your database. On top of clientside validation, model-level validations provide an extra layer of security for any and all form fields within a Ruby on Rails application.
When does validation actually occur?
Straight from the ruby on rails documentation:
There are two kinds of Active Record objects: those that correspond to a row inside your database and those that do not. When you create a fresh object, for example using the new
method, that object does not belong to the database yet. Once you call save
upon that object it will be saved into the appropriate database table. Active Record uses the new_record?
instance method to determine whether an object is already in the database or not.
Continue reading this on my blog: https://web-crunch.com/understanding-activerecord-validations-ruby-on-rails
====================
π° Subscribe: https://www.youtube.com/user/webcrunchblog?sub_confirmation=1
ππ€ NEW COURSE: HELLO RAILS - Get notified Https://hellorails.io
π» Previously published at: https://web-crunch.com/understanding-activerecord-validations-ruby-on-rails
π» Check out the blog: https://web-crunch.com
π¦ Check out my personal site: https://justalever.com
π Links: Weekly Newsletter: https://web-crunch.com/subscribe Twitter: https://twitter.com/webcrunchblog Twitter(Personal Account): https://twitter.com/justalever Facebook: https://facebook.com/webcrunchblog Dribbble: https://dribbble.com/justalever Github: https://github.com/justalever Medium: https://medium.com/the-web-crunch-publication
πCheck out my book on UX Design: "LUXD: Learn User Experience Design" https://web-crunch.com/books/luxd
π Check out my FREE book on Tumblr Theming: "Pro Tumblr Theming" https://web-crunch.com/books/ptt
π― Need awesome web hosting? Check out cloudways. They allow me to use a variety of hosting providers and build apps with ease: http://bit.ly/webcrunchhosting
π Need more advanced hosting for Rails, PHP, Node, or other projects? Digital Ocean has you covered. https://m.do.co/c/ee243ee15648
π Ruby on Rails devs, Try HatchBox.io. You'll save upwards of 50% compared to Heroku. I use it and love it! https://hatchbox.io/?via=andy
βοΈ ππ» Patreon https://www.patreon.com/webcrunch
βοΈ Or buy me a coffee https://www.buymeacoffee.com/webcrunch ... https://www.youtube.com/watch?v=c3hoXWO_6ao
51938215 Bytes