Skip to content

Instantly share code, notes, and snippets.

@sbatson5
Created March 3, 2016 19:13
Show Gist options
  • Save sbatson5/fa19746f30161f01fb02 to your computer and use it in GitHub Desktop.
Save sbatson5/fa19746f30161f01fb02 to your computer and use it in GitHub Desktop.
CreateRecord
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle'
});
<h1>Welcome to {{appName}}</h1>
<br>
<br>
{{outlet}}
<br>
<br>
import DS from 'ember-data';
const {
Model,
attr
} = DS;
export default Model.extend({
title: attr('string'),
author: attr('string')
});
import Ember from 'ember';
import config from './config/environment';
const Router = Ember.Router.extend({
location: 'none'
});
Router.map(function() {
this.route('test-route');
});
export default Router;
import Ember from 'ember';
const {
Route,
on
} = Ember;
export default Route.extend({
beforeModel() {
this.store.createRecord('post', {
author: 'Bilbo Baggins',
title: 'Hobbit Adventures'
})
},
model() {
return this.store.peekAll('post');
},
actions: {
addPost() {
this.store.createRecord('post', {
author: 'Bob Barker',
title: 'Price is right'
})
}
}
});
<h1>We are testing</h1>
{{#each model as |post|}}
<h2>Author: {{post.author}}</h2>
<h2>Title: {{post.title}}</h2>
{{/each}}
<a {{action "addPost"}}>Add post</a>
{
"version": "0.6.1",
"EmberENV": {
"FEATURES": {}
},
"options": {
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/2.3.1/ember.debug.js",
"ember-data": "https://cdnjs.cloudflare.com/ajax/libs/ember-data.js/2.3.3/ember-data.js",
"ember-template-compiler": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/2.2.0/ember-template-compiler.js"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment