Created
June 15, 2013 00:40
-
-
Save simpleshadow/5786276 to your computer and use it in GitHub Desktop.
Boom! This allows `{{linkTo}}` transitions and direct URL loads. Needed to utilize `Ember.Route`'s `model` function (for direct URL) and `setupController` (for `{{linkTo}}` transitions).
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
App.Router.map(function() { | |
this.resource('happs', function() { | |
this.route('new'); | |
this.resource('happ', { path: ':happ_name'}, function() { | |
this.route('edit'); | |
}); | |
}); | |
}); | |
App.HappsRoute = Ember.Route.extend({ | |
model: function() { | |
return App.Happ.findAll(); | |
}, | |
setupController: function(controller, model) { | |
return App.Happ.findAll(); | |
} | |
}); | |
App.HappRoute = Ember.Route.extend({ | |
model: function(param) { | |
var name = param.happ_name.replace(/-/g, ' '); | |
// console.log('model:param', name, Ember.typeOf(name)); | |
return App.Happ.find(name); | |
}, | |
setupController: function(controller, model) { | |
var name = this.modelFor("happ"); | |
if (Ember.typeOf(name) == 'instance') { | |
name = name.get('name'); | |
} | |
name = name.replace(/-/g, ' '); | |
this.controllerFor('happ').set('model', App.Happ.find(name)); | |
// console.log('setupController:name', name, Ember.typeOf(name)); | |
// return App.Happ.find(name); | |
} | |
/* deserialize: function(model) { | |
var name = model.happ_name.replace(/-/g, ' '); | |
console.log('deserialize', { happ_name: name }); | |
return { happ_name: name }; | |
}, | |
serialize: function(model, params) { | |
console.log('serialize', model, params); | |
// return {} | |
}*/ | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment