How to build reusable validations in Ruby on Rails

Опубликовано: 19 Февраль 2026
на канале: Mike Rogers
1,088
44

You can build some super reusable validations by extending the ActiveModel::EachValidator class. Here is a very quick run through on how to do that :)

Sources

➡ https://api.rubyonrails.org/classes/A...
➡ https://github.com/MikeRogers0-YouTub...

Chapters

0:00 - What are we going to do
0:30 - Custom Validations
2:21 - What arguments are available to validate_each
4:53 - Testing with RSpec
7:10 - Our first RSpec test
10:40 - 100% code coverage
11:23 - Why do we need attributes: { any: true } ?
11:09 - Thank you


Follow Me Online

➡ Blog: https://mikerogers.io/
➡ Twitter:   / mikerogers0  
➡ GitHub: https://github.com/mikerogers0
➡ YouTube:    / mikerogers0  
➡ BuyMeACoffee: https://www.buymeacoffee.com/MikeRogers0
➡ Dev.to: https://dev.to/mikerogers0

#RubyOnRails #RSpec #Validation