Skip to content

Instantly share code, notes, and snippets.

@abhilashlr
Last active June 1, 2018 06:46
Show Gist options
  • Save abhilashlr/5b3175b92732d04e6132040271d0b911 to your computer and use it in GitHub Desktop.
Save abhilashlr/5b3175b92732d04e6132040271d0b911 to your computer and use it in GitHub Desktop.
New Twiddle
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle'
});
import Model from 'ember-data/model';
import attr from 'ember-data/attr';
export default Model.extend({
name: attr()
});
import Ember from 'ember';
import config from './config/environment';
const Router = Ember.Router.extend({
location: 'none',
rootURL: config.rootURL
});
Router.map(function() {
this.route('new');
this.route('list');
});
export default Router;
import Ember from 'ember';
export default Ember.Route.extend({
model() {
return this.get('store').peekAll('book');
}
});
import Ember from 'ember';
export default Ember.Route.extend({
model() {
return this.get('store').createRecord('book', {
name: 'dummy'
});
},
// Uncomment the following lines to see that the list cleans up
/*
resetController(controller, isExiting) {
if (isExiting) {
controller.get('model').rollbackAttributes();
}
}
*/
});
{{#link-to 'new'}}
New record
{{/link-to}}
<br />
{{#link-to 'list'}}
List all records
{{/link-to}}
<br>
<br>
Visit new record first then navigate to list all records.
<br />Keep repeating untill you see the dummy records being created
{{outlet}}
Listing::
{{#each model as |data|}}
Name: {{data.name}} <br />
{{/each}}
{
"version": "0.13.1",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "2.16.2",
"ember-template-compiler": "2.16.2",
"ember-testing": "2.16.2"
},
"addons": {
"ember-data": "2.16.3"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment