Skip to content

Instantly share code, notes, and snippets.

@patrickberkeley
Last active January 31, 2016 23:34
Show Gist options
  • Save patrickberkeley/a1ea71038aac5dfcec76 to your computer and use it in GitHub Desktop.
Save patrickberkeley/a1ea71038aac5dfcec76 to your computer and use it in GitHub Desktop.
New Twiddle
import DS from 'ember-data';
export default DS.FixtureAdapter.extend();
import Ember from 'ember';
export default Ember.Controller.extend({
appName:'Ember Twiddle'
});
import Ember from 'ember';
export default Ember.Route.extend({
});
<h1>Welcome to {{appName}}</h1>
<br>
<br>
{{link-to 'Products' 'products'}}
<br>
{{outlet}}
<br>
<br>
import DS from 'ember-data';
var Book = DS.Model.extend({
title: DS.attr('string'),
author: DS.belongsTo('author', { async: true })
});
Book.reopenClass({
FIXTURES: [
{
id: 1,
title: 'Learn Ember.js',
author: 1
},
{
id: 2,
title: '...',
author: 2
},
{
id: 3,
title: 'Profit!',
author: 2
}
]
});
export default Book;
import DS from 'ember-data';
var Product = DS.Model.extend({
name: DS.attr('string')
});
Product.reopenClass({
FIXTURES: [
{
id: 1,
name: 'shirt'
},
{
id: 2,
name: 'pants'
}
]
});
export default Product;
import Ember from 'ember';
export default Ember.Route.extend({
model(params) {
return this.store.find('product', params.id);
}
});
import Ember from 'ember';
export default Ember.Route.extend({
model() {
return this.store.findAll('product');
}
});
<ul>
{{#each model as |product|}}
<li>
{{link-to product.name 'product.show.books' product.id}}
</li>
{{/each}}
</ul>
{{outlet}}
import Ember from 'ember';
import config from './config/environment';
const Router = Ember.Router.extend({
location: config.locationType
});
Router.map(function() {
this.route('products', function() {
this.route('show', { path: ':id' }, function() {
this.route('books');
});
});
});
export default Router;
{
"version": "0.5.0",
"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/1.13.9/ember.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