nullnullnull
nullnullnull

Reputation: 8189

Manually saving a JSON record with Ember-Data

I'm using Ember 1.0 and Ember-Data 1.0beta. I have a situation in which I must step outside of Ember convention and manually create a new record. I'm doing this through an ajax call:

  Ember.$.ajax
    url: '/votes'
    type: "POST"
    data:
      "auth_token": Whistlr.Auth.get('authToken')
      "vote[voteable_type]": @get 'voteableType'
      "vote[voteable_id]": @get 'voteableId'
      "vote[value]": @get 'value'
    success: (response) =>
      ? ? ? ?

The upload works, but I'm unsure how to handle the response. How do I tell Ember-Data to save the json? Something like:

@store.save(response)

This approach doesn't work because I don't have access to the store in this context. I'm also unsure what to pass to the save method. I'm assuming raw json won't work.

Upvotes: 0

Views: 1444

Answers (1)

Edu
Edu

Reputation: 2520

If you need to have access to the store make this an action of router or controller and for handle the response you can use store.push() http://emberjs.com/api/data/classes/DS.Store.html#method_push

good luck

Upvotes: 1

Related Questions