Skip to content

Instantly share code, notes, and snippets.

@troyscott
Created June 8, 2014 21:44
Show Gist options
  • Save troyscott/4ebf431c8be1e8c5ccc1 to your computer and use it in GitHub Desktop.
Save troyscott/4ebf431c8be1e8c5ccc1 to your computer and use it in GitHub Desktop.
Example of a simple EmberJS application that returns a list of contacts from the local memory database (fixture adapter) or from a RESTful service if the fixture adapter is commented out. Click here for the template: https://gist.github.com/troyscott/290611f8f72a2fa7a95a
App = Ember.Application.create();
// Local In Memory Data Store
// Comment this out to defualt to the RESTful Adapter
App.ApplicationAdapter = DS.FixtureAdapter;
App.Contact = DS.Model.extend({
first: DS.attr(),
last: DS.attr(),
phone: DS.attr()
});
// Seed the In Memory database
App.Contact.FIXTURES = [
{ id: 1, first: 'Bob', last: 'Smith', phone: '(777) 999 9999'},
{ id: 2, first: 'Jane', last: 'Smith', phone: '(888) 555 4444'}
]
// Router
App.Router.map(function() {
this.resource('contacts', function() {
this.resource('contact', { path: '/contacts_id' }, function() {
this.route('edit');
});
this.route('create');
}); // users
}); // router
// Users
App.ContactsRoute = Ember.Route.extend({
model: function() {
return this.store.find('contact');
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment