Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ---
- layout: post
- title: "errors.js - Client Side Errors Object"
- date: 2012-03-30 02:05
- comments: false
- categories: javascript, errors, rails, client
- ---
- Despite my opinions of ActiveModel::Validations (a post/patch for another day),
- I like ActiveModel's Errors object. Errors's simplicity, uniquity, and
- consistency is a great boon for handling error messages of varying entities.
- The future of the web is asynchronous and client side computation is steadily becoming more
- sophisticated and well practiced.
- So let's say you've either fired off an asynchronous request or client side
- validation that generated errors, errors.js provides an Errors object similar
- to ActiveModel's Errors object to provide a simple, ubiquitous, consistent
- interface to handle and use error messages on the client side.
- Here's error.js's source,
- {% gist 2246787 %}
- It's small and really simple, and only depends on underscore.js. A complete use of it would look something like
- this,
- I toyed with actually implementing the handler, but then I'd have to parse the
- response and I currently don't want to depend on something like jQuery.
- people.js, to initialize our events and objects,
- {% gist 2246796 %}
- people\_controller, to do what controllers do,
Add Comment
Please, Sign In to add comment