~/talk

Off the Rails: Validating non-model classes with…ActiveModel?

Talkat RailsConf 2025 · 2025-07-08..07-10· [ruby-on-rails]
links:none on file
slides:none on file

Builds a single validator class that accepts Hash/Struct/Data and runs ActiveModel validations (built‑in and custom), using TDD and by reading validators plus ActiveSupport callbacks so options like if and allow_blank behave correctly. Handles presence, confirmation, arrays, shoulda‑matchers quirks, and a mutating‑hash bug fixed by swapping delegator for method_missing. The implementation lives in a repo as a gem scaffold with commit checkpoints and has run in production for over a year.

AI-written summary · about

  1. 0:00Introduction
  2. 1:48Rails validators outside models
  3. 6:20Goals for flexible validator
  4. 7:03Proof of concept: presence validator
  5. 10:54Fixing initial POC errors
  6. 12:21Rails validator options like allow_nil
  7. 14:05Delegating validation methods
  8. 15:07Conditional validations with if/unless
  9. 16:09Hash keys to method calls
  10. 17:29Additional Rails validators
  11. 18:11Clearing validators and state
  12. 19:58Nested data and custom validators
  13. 21:23Class-level validate method
  14. 22:27Confirmation validator quirks
  15. 23:10Shoulda Matchers integration
  16. 24:14Q&A: Hash mutation and use cases
  17. 26:00Q&A: Real-world validation scenarios
  18. 27:02Q&A: Event sourcing and validation
  19. 28:46Q&A: Storing registered validations
  20. 30:08Closing
~/search
type to search 6,249 conferences, 138,987 speakers and 185,172 talks
~/help
cmdctrl k
search every conference, speaker and series
/
focus the filter search
h
home
c
conferences
s
speakers
e
series
t
light / dark — the status bar button does the same
?
this help
esc
close this, then clear every filter — or just the search, while you are typing in it

Ignored while you are typing. Pages without a filter rail have no search to focus.