Tobias L. Maier


110 Experience
1 Lesson Completed
0 Questions Solved


Posted in Normalizes method in ActiveRecord Discussion

This is a great feature.

The greatest disadvantage is, that it only works with ActiveRecord and not with ActiveModel.
This means you cannot use it for Form Objects or other, non-ActiveRecord-baked classes.
I opened a feature request. Hopefully, it will be migrated to ActiveModel some day.

I also wrote a small blog post about how to increase reusability and testability of this.

This would lead to the introduction of normalization pipelines:

class User < ActiveRecord::Base
  normalizes :email, with:, BlankNormalizer, -> { _1&.downcase })