Skip to content

Instantly share code, notes, and snippets.

@benpickles
Created March 31, 2010 16:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benpickles/350520 to your computer and use it in GitHub Desktop.
Save benpickles/350520 to your computer and use it in GitHub Desktop.
ActiveModel-style (Rails 3) `errors.to_json` for your Rails 2 app
module ActiveRecord
class Errors
def to_json
inject({}) { |hash, error|
attribute, message = error
hash[attribute] ||= []
hash[attribute] << message
hash
}.to_json
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment