Created
November 24, 2012 21:57
-
-
Save multiplier/4141546 to your computer and use it in GitHub Desktop.
backbonejserror
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
| class Trainer.Views.LessonsIndex extends Backbone.View | |
| template: JST['lessons/index'] | |
| initialize: -> | |
| @collection.on('reset', @render, this); | |
| @collection.on('add', @render, this); | |
| render: -> | |
| $(@el).html(@template(lessons: @collection)) | |
| this | |
| events: | |
| 'submit #new_lesson': 'createLesson' | |
| createLesson: (event) -> | |
| event.preventDefault() | |
| attributes= | |
| title: $('#new_lesson_title').val(), | |
| description: $('#new_lesson_description').val() | |
| @collection.create attributes, | |
| success: -> $('#new_lesson')[0].reset() | |
| error: @handleError | |
| handleError: (lesson, response) -> | |
| if response.status == 422 | |
| errors = $.parseJSON(response.responseText).errors | |
| for attribute, messages of errors | |
| alert "#{attribute} #{message}" for message in messages |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment