I have a controller for a new resource that, on saving, intends to transition to its page and then fire off a flash notification. I can't get the flash notification to work.
App.StoriesNewController = Ember.ObjectController.extend
...
actions:
updateStory: ->
if @get('model.isValid')
@get('model')?.save().then (data) =>
@transitionTo('story', @get('model'))
Example.flash(success: 'The story was successfully updated.')
, (reason) =>
message = (e for _, e of reason.errors).join("\n")
Example.flash(error: message)
else
Example.flash(error: 'Please fill out required fields')
return false
I have tried putting the flash before the transition, after the transition, or as the result of a promise, e.g.
@transitionTo('story', @get('model')).then =>
Example.flash(success: 'The story was successfully updated.')
None of these work. The only one I've gotten to work is to use a timeout:
@transitionTo('story', @get('model')).then =>
setTimeout(->
Example.flash(success: 'The story was successfully updated.')
, 100)
But this feels especially inelegant. Is there a better way to do this?