escalant3 / ember-data-tastypie-adapter

An adapter to connect django applications powered by django-tastypie with ember.js apps
MIT License
102 stars 26 forks source link

TypeError: method is undefined #11

Closed ricardogsilva closed 11 years ago

ricardogsilva commented 11 years ago

Hi

I'm not very experienced with javascript and I'm having a hard time connecting my tastypie API to an emberjs app.

My tastypie resource:

class GardenResource(ModelResource):
    files = fields.ManyToManyField(MediaResource, 'files')
    class Meta:
        always_return_data = True
        queryset = horta.models.Garden.objects.all()
        resource_name = 'garden'
        fields = ['name']

If I make a call to the API using cURL:

$ curl -H "Accept: application/json" "http://127.0.0.1:8000/api/v1/garden/"

I get back:

{
    "meta": {
        "limit": 20, 
        "next": null, 
        "offset": 0, 
        "previous": null, 
        "total_count": 2
    }, 
    "objects": [
        {
            "files": [], 
            "name": "Horta da Velha", 
            "resource_uri": "/api/v1/garden/1/"
        }, 
        {
            "files": [], 
            "name": "Horta da Costa", 
            "resource_uri": "/api/v1/garden/2/"
        }
    ]
}

The ember js file:

var HortaApp = Ember.Application.create();
HortaApp.store = DS.Store.create({
    revision : 11,
    adapter : DS.DjangoTastypieAdapter.extend({
        serverDomain : 'http://127.0.0.1:8000',
        namespace : 'api/v1',
    }),
});

/* Models */
HortaApp.Garden = DS.Model.extend({
    name : DS.attr('string'),
});

/* Views */
HortaApp.ApplicationView = Ember.View.extend({
    templateName : 'application',
});

HortaApp.AllGardensView = Ember.View.extend({
    templateName : 'all-gardens',
});

/* Controllers */
HortaApp.ApplicationController = Ember.Controller.extend();
HortaApp.AllGardensController = Ember.ArrayController.extend();

/* Routers */
HortaApp.Router = Ember.Router.extend({
    enableLogging : true,
    root : Ember.Route.extend({
        index : Ember.Route.extend({
            route : '/',
            connectOutlets : function(router){
                router.get('applicationController').connectOutlet(
                    'allGardens', HortaApp.Garden.find()
                );
            },
        }),
    }),
});

HortaApp.initialize();

When I run it through firebug I get:

STATEMANAGER: Entering root
STATEMANAGER: Sending event 'navigateAway' to state root.
STATEMANAGER: Sending event 'unroutePath' to state root.
STATEMANAGER: Sending event 'routePath' to state root.
STATEMANAGER: Entering root.index

TypeError: method is undefined
return method.apply(target || this, args || []);

It seems there is something wrong with the setting up of the models, as it doesn't even get to making the request to the server. What could be the problem?

Thanks

escalant3 commented 11 years ago

Which version of ember are you using? That is the old router API

ricardogsilva commented 11 years ago

Yeah, it was an error with outdated versions. I was using ember1.0.0-pre.2. I have switched to pre.4 and I don't have this error anymore. Thanks