Need help getting Ember-Data working with Zend Rest.
At first, I’m familiar with Zend Framework, so the Rest Adapter was easy to setup. Requests by telnet show it works and response also has well-formed HTTP codes.
The setup with Ember Data was a little more complicated. I installed a VM with Ubuntu, installed Ruby 1.9.3, git cloneed the ember-data repository and generated the JS file with rake. I also installed the bundler to resolve all dependencies. Seems to work with no errors.
This was the first time for me. I’m not familiar with ruby.
Unfortuately, it does not appear to be working. On my test app I see with firebug the rest request. The response looks also good. But the object is still empty.
The response:
[{"id":"1","user":"testuser","password":"123","mail":"my@me.com","role":"GUEST","active":"1","hash":null,"last_login":null}]
response headers:
Cache-Control no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Connection Keep-Alive
Content-Encoding gzip
Content-Length 121
Content-Type application/json; charset=utf-8
Date Wed, 20 Jun 2012 10:49:38 GMT
Expires Thu, 19 Nov 1981 08:52:00 GMT
Keep-Alive timeout=15, max=99
Pragma no-cache
Server Apache
Vary Accept-Encoding
X-Powered-By PHP/5.3.13
X-UA-Compatible IE=Edge,chrome=1
My App:
// my script
App = Em.Application.create();
App.store = DS.Store.create({
revision: 4,
adapter: DS.RESTAdapter.create({ bulkCommit: false, namespace: 'rest' })
});
App.User = DS.Model.extend({
id: DS.attr('number'),
user: DS.attr('string'),
password: DS.attr('string'),
mail: DS.attr('string'),
role: DS.attr('string'),
active: DS.attr('number'),
hash: DS.attr('string'),
last_login: DS.attr('date')
});
App.postsController = Em.ArrayController.create({
content: App.store.findAll(App.User)
});
// my html page
<script type="text/x-handlebars">
{{#each App.postsController}}
<li>{{user}}</li>
{{/each}}
</script>
What am I doing wrong? I’m not sure my ember-data.js is working.
https://github.com/emberjs/data/issues/132
DS.RESTAdapter requires a root element. Such as:
This is because DS.RESTAdapter supports side loading. Unfortunately, it is not configurable. The only way around this requirement is to roll your own adapter.