ken
ken

Reputation: 8993

Leading character stripped off of API call

I am attempting to setup a REST model and have a problem that is completely befuddling me: the API call that is generated seems to remove the first letter of the model and therefore is unable to retrieve the data (gets 404 error).

I start by setting up the store:

App.Store = DS.Store.extend({
    revision: 11,
    adapter: DS.RESTAdapter.reopen({
        namespace: 'api/admin'
    })
});

Then I setup a model (which is referred to as "dbx_tables" on the REST service:

App.dbxTable = DS.Model.extend({
    name: "string",
    db_column: "string"
});

Then there is the route:

App.DbxRoute = Ember.Route.extend({
    model: function() {
        return App.dbxTable.find();
    }
});

I've turned on the logging of transitions:

App = Ember.Application.create({
    LOG_TRANSITIONS: true
});

So when I start the application it transitions first to the "about" page and then I click over to the "dbx" view (I'm not sure why it says dbx.index rather than just dbx):

DEBUG: ------------------------------- ember-1.0.0-rc.1.js:339
DEBUG: Ember.VERSION : 1.0.0-rc.1      ember-1.0.0-rc.1.js:339
DEBUG: Handlebars.VERSION : 1.0.0-rc.3 ember-1.0.0-rc.1.js:339
DEBUG: jQuery.VERSION : 1.9.1          ember-1.0.0-rc.1.js:339
DEBUG: ------------------------------- ember-1.0.0-rc.1.js:339
Transitioned into 'about'              ember-1.0.0-rc.1.js:339
Transitioned into 'dbx.index'          ember-1.0.0-rc.1.js:339
GET http://lifegadget-local/api/admin/bx_tables 404 (Not Found) jquery-1.9.1.js:8526

notice the reference to bx_tables in the API call. How did the leading "d" get removed? I also wasn't sure why it pluralized the call although that could easily fit into convention so not really worried about that.

Upvotes: 4

Views: 244

Answers (2)

Neal
Neal

Reputation: 4558

I had the same issue. My problem was:

this.get('store').findAll('user');   

needed to be changed to:

this.get('store').findAll('User');   

Upvotes: 6

ken
ken

Reputation: 8993

Ok, looks like I made a "convention error" and the model's lack of capitalisation was what was causing the problems. So by switching the App.dbxTable to App.DbxTable I have now sorted out the problem.

Upvotes: 1

Related Questions