I'm trying to figure out how to use a slug (attribute of my model) in my ember routes to get cleaner urls.
I'd like that my routes look like this:
http://www.server.com/#/newsitems/newsitem-title-in-slug-format/1
Instead of:
http://www.server.com/#/newsitems/1/1
As you can see, I'd like to replace the id of the newsitem with the actual slug attribute. Here's how my Newsitem
model looks like:
App.Newsitem = DS.Model.extend({
slug: DS.attr('string'),
title: DS.attr('string'),
summary: DS.attr('string'),
});
The slug property receives a clean text attribute in this format: title-in-slug-format
This is my router map at the moment:
App.Router.map(function(){
this.resource('newsitems', function(){
this.resource('newsitem', {path:':newsitem_id'});
});
});
I tried replacing the newsitem_id
with newsitem_slug
but this isn't working. Any other suggestions?
Big thanks to Michael for pointing me in the right direction. But, and I think this is because I'm working in the rc-1 version of ember, I didn't had to override the model hook for this. The only thing I had to do is:
App.NewsitemRoute = Ember.Route.extend({
serialize: function(model, params) {
return { newsitem_id: model.get('slug') };
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With