Skip to content

Instantly share code, notes, and snippets.

@simpleshadow
Created June 15, 2013 00:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save simpleshadow/5786276 to your computer and use it in GitHub Desktop.
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).
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