Skip to content

Instantly share code, notes, and snippets.

@christianvuerings
Created January 20, 2012 22:28
Show Gist options
  • Save christianvuerings/1649982 to your computer and use it in GitHub Desktop.
Save christianvuerings/1649982 to your computer and use it in GitHub Desktop.
def translate_errors(record)
ret = {}
record.errors.each do |key, message|
keystring = key.to_s
if keystring.include? '_content_type'
keystring.gsub!('_content_type', '')
key = keystring.to_sym
end
# Happens when you try to submit an invalid file (e.g. zip) as a screenshot
if keystring.include? '.'
keystring.gsub!('.', '_')
key = keystring.to_sym
message = message.split(".")[0]
end
ret[key] = {
:title => record.class.human_attribute_name(key),
:message => message
}
end
ret
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment