2

My Ember router pings the server for a photos JSON file every 5 seconds (long polling). It loops over the JSON and adds (using EmberData's push) a photo to the store if the photo id does not yet exist. Using the workflow described by Yoran Brondsema.

A snippet from the JSON file:

...
{
  "id": 45,
  "created_at": "2014-06-02T08:10:29.000Z"
}
...

Ember.js converts the created_at snake_case to the createdAt camelCased version and when I reload the page everything looks fine. The {{createdAt}} is available in the Handlebars template. But...

When the poller adds the photo model to the store the createdAt camelCased attribute is undefined. It works when I rename it the field in the JSON file to createdAt using camelCasing.

Should I not expect the camelCased attributes to be there when pushing to the store? Is the store outdated? Is it a timing issue where Ember didn't convert the attribute yet?

My store adapter looks like this:

App.ApplicationStore = DS.Store.extend({});
App.ApplicationAdapter = DS.ActiveModelAdapter.extend({
  namespace: 'api'
});

It's a Rails backend (using ActiveModel::Serializer) but don't think that has anything to do with it.

Thanks!

Community
  • 1
  • 1
Cimm
  • 4,653
  • 8
  • 40
  • 66

1 Answers1

1

Found it, the code from the post mentioned in the question does not use the Ember Data RESTAdapter so Ember does not convert the snake_cases from the JSON response.

Cimm
  • 4,653
  • 8
  • 40
  • 66