Created
June 8, 2009 10:49
-
-
Save nikz/125757 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # BEFORE | |
| >> a = User.new; a.valid? | |
| >> a.errors.to_json | |
| => "[["name", "can't be blank"], ["password_confirmation", "can't be blank"], ["password", "can't be blank"], ["password", "is too short (minimum is 6 characters)"], ["email", "can't be blank"], ["email", "is too short (minimum is 6 characters)"], ["email", "should look like an email address."]]" | |
| # config/initializers/sane_errors_to_json.rb | |
| module ActiveRecord | |
| class Errors | |
| def to_json | |
| @errors.to_json | |
| end | |
| end | |
| end | |
| # AFTER | |
| >> a = User.new; a.valid? | |
| >> a.errors.to_json | |
| => "{"name": ["can't be blank"], "password_confirmation": ["can't be blank"], "password": ["can't be blank", "is too short (minimum is 6 characters)"], "email": ["can't be blank", "is too short (minimum is 6 characters)", "should look like an email address."]}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment