I'm trying to do a custom url.

More specifically, what I've already done is: mypage.com/details/1

What I'd like to do is: mypage.com/details/john-doe

Of course, I want exactly the same behavior as now, with the sole difference being a custom string instead of id

Here's my DS model

App.Images.FIXTURES = [
{
            id:1,
            name: "John",
            lastName: "Doe",
            age: 25,
            customUrl: "john-doe"
},
{
            id:2,
            name: "John",
            lastName: "Doe",
            age: 31,
            customUrl: "john-doe1"
}];

*Note the customUrl attribute which is unique.

My routes:

App.Router.map(function(){
        this.resource("details", {path: 'details/:image_id'});
    });

And the according html:

{{#linkTo 'details' this}}The details{{/linkTo}}

What are my options? Putting "this" in html automatically grabs the ID. I tried this.customUrl with no luck (I get the "undefined" value in the url).

Thank you for your help!

有帮助吗?

解决方案

you can override serialize in router to return customUrl instead of id

App.DetailsRoute = Ember.Route.extend({
    //   ....
    serialize: function(model) {
        return { details_id: model.get('customUrl') };
    }
});
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top