Forem

Augusts Bautra
Augusts Bautra

Posted on

2

TIL use `normalizes :field, apply_to_nil: true`

tl;dr

Use normalizes :boolean_field, apply_to_nil: true, with: -> { _1.present? }.

Today I got a nasty little surprise from the otherwise excellent normalizes macro. Turns out it does not normalize nil values out of the box. This bit me in the ass because I'm working on eliminating nil values from boolean fields and hadn't bothered checking whether it works. Now I need to review all the normalizes statements I've added recently, sigh.

You can read more about the macro on apidoc.

Top comments (0)

AWS Security LIVE!

Tune in for AWS Security LIVE!

Join AWS Security LIVE! for expert insights and actionable tips to protect your organization and keep security teams prepared.

Learn More