Guest User

Untitled

a guest
Sep 21st, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. ---
  2. layout: post
  3. title: "errors.js - Client Side Errors Object"
  4. date: 2012-03-30 02:05
  5. comments: false
  6. categories: javascript, errors, rails, client
  7. ---
  8.  
  9. Despite my opinions of ActiveModel::Validations (a post/patch for another day),
  10. I like ActiveModel's Errors object. Errors's simplicity, uniquity, and
  11. consistency is a great boon for handling error messages of varying entities.
  12.  
  13. The future of the web is asynchronous and client side computation is steadily becoming more
  14. sophisticated and well practiced.
  15.  
  16. So let's say you've either fired off an asynchronous request or client side
  17. validation that generated errors, errors.js provides an Errors object similar
  18. to ActiveModel's Errors object to provide a simple, ubiquitous, consistent
  19. interface to handle and use error messages on the client side.
  20.  
  21. Here's error.js's source,
  22.  
  23. {% gist 2246787 %}
  24.  
  25. It's small and really simple, and only depends on underscore.js. A complete use of it would look something like
  26. this,
  27.  
  28. I toyed with actually implementing the handler, but then I'd have to parse the
  29. response and I currently don't want to depend on something like jQuery.
  30.  
  31.  
  32. people.js, to initialize our events and objects,
  33.  
  34. {% gist 2246796 %}
  35.  
  36. people\_controller, to do what controllers do,
Add Comment
Please, Sign In to add comment