ChickenFur
ChickenFur

Reputation: 2400

How to update backbone.model.updated_at after a model.save

When I save a model I want to get the updated_at value from the server.

Currently I do:

#Save My model
@model.save()
@listenToOnce @model, "sync", () =>
  #my ruby on rails server returns the asset with the new updated time
  #get the updated time from the server
  @model.fetch()
  @listenToOnce @model, "sync", () => 
    #now my model has the new updated time here.

The code on the server side:

if anAsset.save!()
      respond_with anAsset

It works, but I know I shouldn't be making two trips to the server. Why doesn't the updated_at time sync with the backbone model.save() call? Is there a way I can get it with just one trip to the server?

Thanks!

Upvotes: 1

Views: 125

Answers (1)

mu is too short
mu is too short

Reputation: 434755

If all you care about is JSON, then cut to the chase and say so:

render :json => anAsset, :status => :ok

You can mess around with all the magical respond_to :json and respond_with anAsset stuff if you want but I find that that stuff just confuses things when you're only speaking JSON.

Upvotes: 1

Related Questions