Sha256: 5eefbaebaf1207939c482ce6336399da43433d10889654fcd9fee7ac98a060bd
Contents?: true
Size: 688 Bytes
Versions: 8
Compression:
Stored size: 688 Bytes
Contents
module Granite module Form module Model module Validations class AssociatedValidator < ActiveModel::EachValidator def validate_each(record, attribute, value) invalid_records = Array.wrap(value).reject do |r| r.respond_to?(:valid?) && r.valid?(record.validation_context) end record.errors.add(attribute, :invalid, **options.merge(value: value)) if invalid_records.present? end end module HelperMethods def validates_associated(*attr_names) validates_with AssociatedValidator, _merge_attributes(attr_names) end end end end end end
Version data entries
8 entries across 8 versions & 1 rubygems