this patch expands the #full_messages of errors of the :custom_fields attribute to display all the individual errors per custom field

pull/1186/head
Martin Linkhorst 12 years ago
parent a016703c56
commit 6e6dfbbdc2
  1. 29
      config/initializers/10-patches.rb

@ -25,28 +25,37 @@ module ActiveRecord
end
end
module ActiveRecord
module ActiveModel
class Errors
def full_messages(options = {})
def full_messages
full_messages = []
@errors.each_key do |attr|
@errors[attr].each do |message|
@messages.each_key do |attribute|
@messages[attribute].each do |message|
next unless message
if attr == "base"
if attribute == :base
full_messages << message
elsif attr == "custom_values"
elsif attribute == :custom_values
# Replace the generic "custom values is invalid"
# with the errors on custom values
@base.custom_values.each do |value|
value.errors.each do |attr, msg|
full_messages << value.custom_field.name + ' ' + msg
full_messages += value.errors.map do |_, message|
I18n.t(:"errors.format", {
:default => "%{attribute} %{message}",
:attribute => value.custom_field.name,
:message => message
})
end
end
else
attr_name = @base.class.human_attribute_name(attr)
full_messages << attr_name + ' ' + message.to_s
attr_name = attribute.to_s.gsub('.', '_').humanize
attr_name = @base.class.human_attribute_name(attribute, :default => attr_name)
full_messages << I18n.t(:"errors.format", {
:default => "%{attribute} %{message}",
:attribute => attr_name,
:message => message
})
end
end
end

Loading…
Cancel
Save