Sha256: 62fd97c3448c3de26289e3910fd4c9c71b341300836d6329dc6e24e30d09e01f
Contents?: true
Size: 1.12 KB
Versions: 146
Compression:
Stored size: 1.12 KB
Contents
module PgEngine module ErrorHelper extend ActiveSupport::Concern # pg_engine/config/initializers/simple_form_monkey_patch.rb def merge_association_errors(object, details, assoc_key) details = details.except(assoc_key) assoc_items = object.send(assoc_key).map(&:errors).map(&:details) merged = assoc_items.inject({}) { |acc, el| acc.merge(el) } merged = merged.transform_values { |errs| errs.pluck(:error) } details.merge(merged) end def error_types(object, associations: []) details = object.errors.details.transform_values do |errs| errs.pluck(:error) end associations.each do |assoc_key| next unless details.key? assoc_key details = merge_association_errors(object, details, assoc_key) end details.values.flatten.uniq end def error_message_for(object, associations: []) types = error_types(object, associations:) if types == [:blank] :only_presence_errors elsif types.include? :blank :multiple_error_types elsif types.present? :not_presence_errors end end end end
Version data entries
146 entries across 146 versions & 1 rubygems