DEV Community

Jorge Alvarez
Jorge Alvarez

Posted on

Normalise array in Rails 7.1

One of the (many) good features of Rails 7.1 is the normalizes method. This is how you can use it with fields of type array.

In this example there is a field called folders that we want to normalise removing blank entries and ensuring all entries are down cased.

normalizes :folders, with: ->(values) { (values || []).map(&:downcase).reject(&:blank?) }
Enter fullscreen mode Exit fullscreen mode

Top comments (0)

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay