Skip to content

Instantly share code, notes, and snippets.

@boy-jer
Forked from darthdeus/route.js
Created April 24, 2013 20:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save boy-jer/5455136 to your computer and use it in GitHub Desktop.
Save boy-jer/5455136 to your computer and use it in GitHub Desktop.
Scvrush.UserEditRoute = Ember.Route.extend({
events: {
saveProfile: function() {
var user = this.controllerFor("user").get("content"),
route = this;
user.one("didUpdate", function() {
route.transitionTo("home");
});
user.get("transaction").commit();
}
},
enter: function() {
var user = this.controllerFor("user").get("content"),
transaction = user.get("store").transaction();
transaction.add(user);
},
exit: function() {
this.controllerFor("user").get("content.transaction").rollback();
},
});
@boy-jer
Copy link
Author

boy-jer commented Apr 24, 2013

alternative approach

 Scvrush.UserEditRoute = Ember.Route.extend({

   model: {
        return this.modelFor('user');
    },

events: { 

 saveProfile: function(user) {
      var route = this;

      user.on("didUpdate", function() {
          route.transitionTo("home");
      });

       user.get("transaction").commit();
 }

},

enter: function() {
 //not sure if currentModel if available at this point. But it usually is later.
   var user = this.currentModel;
   transaction = user.get("store").transaction();

    transaction.add(user);
 },

  exit: function() {
      this.currentModel.get("content.transaction").rollback();
    },

 });

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment