简体   繁体   中英

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!

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM