Created
December 2, 2014 04:10
-
-
Save nataren/20666dc76cfeb644d867 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Error | |
Error while processing route: index undefined is not a function TypeError: undefined is not a function | |
at App.IndexRoute.Ember.Route.extend.model (http://localhost:8080/js/app.js:24:25) | |
at apply (http://localhost:8080/js/lib/ember-1.8.1.js:19674:27) | |
at superWrapper [as model] (http://localhost:8080/js/lib/ember-1.8.1.js:19245:15) | |
at EmberObject.extend.deserialize (http://localhost:8080/js/lib/ember-1.8.1.js:24912:21) | |
at applyHook (http://localhost:8080/js/lib/ember-1.8.1.js:46984:30) | |
at Object.HandlerInfo.runSharedModelHook (http://localhost:8080/js/lib/ember-1.8.1.js:45006:22) | |
at Object.subclass.getModel (http://localhost:8080/js/lib/ember-1.8.1.js:45232:21) | |
at http://localhost:8080/js/lib/ember-1.8.1.js:46858:19 | |
at tryCatch (http://localhost:8080/js/lib/ember-1.8.1.js:47307:16) | |
at invokeCallback (http://localhost:8080/js/lib/ember-1.8.1.js:47319:17)ember-1.8.1.js:15373 logToConsoleember-1.8.1.js:26312 logErrorember-1.8.1.js:26269 defaultActionHandlers.errorember-1.8.1.js:26360 triggerEventember-1.8.1.js:46873 triggerember-1.8.1.js:46718 Transition.triggerember-1.8.1.js:46523 (anonymous function)ember-1.8.1.js:47307 tryCatchember-1.8.1.js:47319 invokeCallbackember-1.8.1.js:47290 publishember-1.8.1.js:47232 publishRejectionember-1.8.1.js:29435 (anonymous function)ember-1.8.1.js:679 DeferredActionQueues.invokeember-1.8.1.js:749 DeferredActionQueues.flushember-1.8.1.js:135 Backburner.endember-1.8.1.js:190 Backburner.runember-1.8.1.js:18223 runember-1.8.1.js:2542 runInitializejquery-1.10.2.js:3048 firejquery-1.10.2.js:3160 self.fireWithjquery-1.10.2.js:433 jQuery.extend.readyjquery-1.10.2.js:104 completed | |
// JS | |
(function() { | |
var App = window.App = Ember.Application.create(); | |
DS.Store.create({ | |
revision: 12, | |
adapter: DS.RESTAdapter.create({ | |
namespace: 'api' | |
}) | |
}); | |
App.Router.map(function() { | |
this.route('create'); | |
this.route('edit', {path: '/edit/:kitten_id'}); | |
}); | |
App.Kitten = DS.Model.extend({ | |
name: DS.attr('string'), | |
picture: DS.attr('string') | |
}); | |
App.IndexRoute = Ember.Route.extend({ | |
model: function() { | |
return App.Kitten.find(); | |
}, | |
events: { | |
deleteKitten: function(kitten) { | |
kitten.deleteRecord(); | |
kitten.save(); | |
} | |
} | |
}); | |
App.CreateController = Ember.Controller.extend({ | |
name: null, | |
save: function() { | |
var kitten = App.Kitten.createRecord({ | |
name: this.get('name') | |
}); | |
kitten.save().then(function() { | |
this.transitionToRoute('index'); | |
this.set('name', ''); | |
}.bind(this)); | |
} | |
}); | |
App.EditController = Ember.ObjectController.extend({ | |
save: function() { | |
var kitten = this.get('model'); | |
kitten.save().then(function() { | |
this.transitionToRoute('index'); | |
}.bind(this)); | |
} | |
}); | |
})(); | |
// HTML | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>Ember.js + Go == ♥</title> | |
<link href="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/css/bootstrap-combined.min.css" rel="stylesheet"> | |
</head> | |
<body> | |
<script type="text/x-handlebars"> | |
<div class="container"> | |
<ul class="nav nav-tabs"> | |
<li>{{#linkTo index}}Index{{/linkTo}}</li> | |
<li>{{#linkTo create}}Create{{/linkTo}}</li> | |
</ul> | |
{{outlet}} | |
</div> | |
</script> | |
<script type="text/x-handlebars" data-template-name="index"> | |
<ul class="thumbnails"> | |
{{#each controller}} | |
<li class="span3"> | |
<div class="thumbnail"> | |
<img {{bindAttr src="picture"}}/> | |
<div class="caption"> | |
<h3>{{name}}</h3> | |
<button {{action deleteKitten this}}>Delete</button> | |
{{#linkTo edit this}}Edit{{/linkTo}} | |
</div> | |
</div> | |
</li> | |
{{/each}} | |
</ul> | |
</script> | |
<script type="text/x-handlebars" data-template-name="_form"> | |
<form {{action save on="submit"}} class="form-inline"> | |
{{input type="text" value=name}} | |
<button type="submit" class="btn btn-primary">Save</button> | |
</form> | |
</script> | |
<script type="text/x-handlebars" data-template-name="create"> | |
<h1>Create kitten</h1> | |
{{partial 'form'}} | |
</script> | |
<script type="text/x-handlebars" data-template-name="edit"> | |
<h1>Edit kitten</h1> | |
{{partial 'form'}} | |
</script> | |
<script src="js/lib/jquery-1.10.2.js"></script> | |
<script src="js/lib/handlebars-v1.3.0.js"></script> | |
<script src="js/lib/ember-1.8.1.js"></script> | |
<script src="js/lib/ember-data.js"></script> | |
<script src="js/app.js"></script> | |
</body> | |
</html> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment