ember.js - Trigger Ember Error Substate in Route Action -


let's have banananewroute that's responsible displaying new banana form , creating banana.

app.banananewroute = ember.route.extend   model: -> @store.createrecord('banana')    actions:         create: @currentmodel.save().then => @transitionto "banana", @currentmodel 

because input of application tightly controlled, it's safe assume if server returns type of error, it's application error , there's nothing user can it. i'd handle transitioning user separate error template whenever save action rejects.

i took @ loading / error substates documentation, seems works model, beforemodel , aftermodel hooks. couldn't work create action. how can accomplish this?

save returns promise. promise's takes both passing , failing function (pardon converted coffeescript).

save().then ((results) ->   console.log "it worked", results   return ), (error) ->   console.log "it failed", error   return 

or in javascript, , breaking down bit

var pass = function(results){}; var fail = function(error){};  save().then(pass, fail); 

to manually transitionto error route, need call

this.transitionto('error', reason); 

example http://emberjs.jsbin.com/xetatoxo/1/edit

the same can done deeper error routes

this.transitionto('foo.error', 'it died'); 

http://emberjs.jsbin.com/xetatoxo/2/edit


Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -