DZone

Ever open up a Rails console to debug a problem and come away wondering how the data got so funky? Despite our best efforts, the database will accept plenty of garbage data if you let it. There are tons of methods to bypass the Rails callbacks and validations while still updating your database. If you are like me you have probably used these methods in the Rails console to fix some of that funky data you found after some other code created it in the first place.

Active Record Validations are a good place to start to prevent the funk. They will check the attributes for presence, absence, numericality, length, inclusion, format, exclusion, acceptance, and more. You can validate your model’s data easily and prevent any number of common errors this way. They aren’t the end of the problem but for most funky data you see your mind should go to checking the validations and probably writing another one. 

Source: DZone