Leading character stripped off of API call

試著忘記壹切 提交于 2019-12-14 01:04:46

问题


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.


回答1:


I had the same issue. My problem was:

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

needed to be changed to:

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



回答2:


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.



来源:https://stackoverflow.com/questions/15734236/leading-character-stripped-off-of-api-call

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!