Skip to content

Instantly share code, notes, and snippets.

@ejfinneran
Created October 20, 2010 06:34
Show Gist options
  • Save ejfinneran/635898 to your computer and use it in GitHub Desktop.
Save ejfinneran/635898 to your computer and use it in GitHub Desktop.
What is up with JSON encoding on ActiveModel::Errors?
ruby-1.8.7-p302 > hash
=> #<OrderedHash {:email=>["is too short (minimum is 6 characters)", "should look like an email address."]}>
ruby-1.8.7-p302 > u.errors
=> #<OrderedHash {:email=>["is too short (minimum is 6 characters)", "should look like an email address."]}>
ruby-1.8.7-p302 > hash == u.errors
=> true
ruby-1.8.7-p302 > hash.to_json == u.errors.to_json
=> false
ruby-1.8.7-p302 > hash.to_json
=> "{\"email\":[\"is too short (minimum is 6 characters)\",\"should look like an email address.\"]}"
ruby-1.8.7-p302 > u.errors.to_json
=> "{\"email\":\"is too short (minimum is 6 characters)\",\"email\":\"should look like an email address.\"}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment