Skip to content

Instantly share code, notes, and snippets.

@alexspeller
Last active December 21, 2015 05:29
Show Gist options
  • Save alexspeller/6257579 to your computer and use it in GitHub Desktop.
Save alexspeller/6257579 to your computer and use it in GitHub Desktop.
MyAdapter = Ember.RESTAdapter.extend
didSaveRecord: (record, data) ->
rootKey = Em.get(record.constructor, 'rootKey')
primaryKey = Em.get(record.constructor, 'primaryKey')
dataToLoad = if rootKey then data[rootKey] else data
if dataToLoad
record.load(dataToLoad[primaryKey], dataToLoad)
record.didSaveRecord()
App.Book.adapter = MyAdapter.create()
# On server
def update
book = Book.find params[:id]
if book.update_attributes params
render json: book
else
raise "didn't save book"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment