Ember Latest

The latest build of Ember.

by marciojunior

HTML

<script src="http://builds.emberjs.com/handlebars-1.0.0.js"></script>
<script src="http://builds.emberjs.com/ember-latest.js"></script>
<script src="https://s3.amazonaws.com/builds.emberjs.com/ember-data-latest.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery-mockjax/1.5.1/jquery.mockjax.js"></script>
<script type="text/x-handlebars" data-template-name="person">
    {{input type="text" valueBinding=name action="save"}}
</script>

CSS

h1 { font-size: 1.6em; padding-bottom: 10px; }
h2 { font-size: 1.4em; }
ul { padding: 15px; font-size: 1.4em; color: green; }

JavaScript

App = Ember.Application.create({});

App.PersonRoute = Ember.Route.extend({
  model: function() {
      return App.Person.createRecord();
  },
    actions: {
        save: function() {
            this.controller.get('model').save();
        }
    }
});

App.Router.map(function() {
    this.route('person', { path: '/' })
})

App.Store = DS.Store.extend({
  revision: 13
});

App.Person = DS.Model.extend({
    name: DS.attr('string') ,
    becameInvalid: function(errors) {        
        alert(errors.get('errors.name').join(','));
    }
});

$.mockjax({
    url: '/persons',
    response: function(settings) {
        var json = {
            errors: {
                name: ['Name is invalid']
            }
        };
        settings.error({ status: 422, responseText: JSON.stringify(json) });
    }
});