Sha256: 4169c58219b6cbd0c231d278e2f0d1d85d5e947faa77f7f05fff82496008397c
Contents?: true
Size: 742 Bytes
Versions: 4
Compression:
Stored size: 742 Bytes
Contents
# Utility class to extract validation errors from ActiveRecord models in a readable fashion. # origin: RM class Error def self.messages(object, options = {}) except = Set.new(options.delete(:except) || []) object.errors.collect do |attribute, _| message(object, attribute) unless except.include? attribute end.compact end def self.message(object, attribute) message = Array(object.errors.on(attribute)) if message.present? message = message.first if message.starts_with?('^') message[1..-1] else translated_attribute = I18n.t("activerecord.attributes.#{object.class.name.underscore}.#{attribute}") "#{translated_attribute} #{message}" end end end end
Version data entries
4 entries across 4 versions & 1 rubygems