Sha256: d28c6fe0cb55867c7122a2f6085c3a505166ede9e6ff58ca97b75ba6740ac251
Contents?: true
Size: 533 Bytes
Versions: 24
Compression:
Stored size: 533 Bytes
Contents
# frozen_string_literal: true module Maglev class CollectionValidator < ActiveModel::EachValidator def validate_each(record, attribute, value) prefix = attribute.to_s.singularize.humanize value.each_with_index do |item, index| next if item.valid? record.errors.add( "#{prefix} ##{index}", "is invalid, reason(s): #{clean_item_errors(item)}" ) end end private def clean_item_errors(item) item.errors.full_messages.join(', ') end end end
Version data entries
24 entries across 24 versions & 1 rubygems