Skip to content

Instantly share code, notes, and snippets.

@kenelliott
Created October 2, 2015 14:56
Show Gist options
  • Save kenelliott/5fb0dd4d7b8358c7c7dd to your computer and use it in GitHub Desktop.
Save kenelliott/5fb0dd4d7b8358c7c7dd to your computer and use it in GitHub Desktop.
New Twiddle
import Ember from 'ember';
export default Ember.Controller.extend({
appName:'Ember Twiddle'
});
import Ember from 'ember';
export default Ember.Route.extend({
model() {
return this.store.createRecord('widget', {name: "Example Model Name"});
},
actions: {
makeError() {
console.log('adding an error');
this.get('currentModel.errors').add('name', 'this is broken');
},
clearError() {
console.log('clearing an error');
this.get('currentModel.errors').remove('name');
}
}
});
<h1>Welcome to {{appName}}</h1>
<div>
{{model.name}}
</div>
<br>
<button {{action "makeError"}}>Make Error</button> |
<button {{action "clearError"}}>Clear Error</button>
<br>
<div>
{{#each model.errors as |error|}}
{{error.message}}
{{/each}}
</div>
import DS from 'ember-data';
export default DS.Model.extend({
name: DS.attr('string')
});
{
"version": "0.4.11",
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/1.13.9/ember.debug.js",
"ember-data": "https://cdnjs.cloudflare.com/ajax/libs/ember-data.js/1.13.11/ember-data.js",
"ember-template-compiler": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/1.13.9/ember-template-compiler.js"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment