dry-schema

Dry Schema: Decouple Validations from Rails Models

Dry Schema: Decouple Validations from Rails Models

Standard Ruby on Rails best practices suggest that we should define our validations on the model object. RoR gives you the tool, aka DSL (domain specific language), to implement these validations. For simple situations, say a signup form, this works really well, but what about more complicated scenarios? What if your model serves several different controllers? Or what if, for example, different types of users could submit different values to the same model? Do we want to use messy ifblocks to check the user type and apply the correct set of validations? Probably not. So what’s the solution? Enter Dry-schema.