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)