Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EmberJS: change url for loading model (ember-data)

I have problems with ember-data. For example, I've created a project at http://localhost/~me/test

In my project I've created a store and a model as follows:

... init stuff here ...

var attr = DS.attr;
App.Person = DS.Model.extend({
    firstName: attr('string'),
    lastName: attr('string'),
});

App.Store = DS.Store.extend({
    revision: 11,
    adapter: DS.RESTAdapter,
});

Now when I search (somewhere in my route) for a person like this

var person = App.Person.find(params);

The http://localhost/persons?post_id=10 is called. This one does not exist of course. I would've expected something like http://localhost/~me/test/persons?post_id=10. Even better would be http://localhost/~me/test/persons.php?post_id=10 How can I change this url ?

like image 214
Jeanluca Scaljeri Avatar asked Jan 18 '13 20:01

Jeanluca Scaljeri


1 Answers

This is as of Ember Data Beta 3

To take care of the prefix, you can use the namespace property of DS.RESTAdapter. To take care of the suffix, you'll want to customize the buildURL method of DS.RESTAdapter, using _super() to get the original functionality and modifying that. It should look something like this:

App.ApplicationAdapter = DS.RESTAdapter.extend({
    namespace: '~me/test',
    buildURL: function() {
        var normalURL = this._super.apply(this, arguments);
        return normalURL + '.php';
    }
});
like image 114
Kerrick Avatar answered Oct 22 '22 04:10

Kerrick