1

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?

AlexQueue
  • 6,353
  • 5
  • 35
  • 44
  • possible duplicate of [Ember transition & rendering complete event](http://stackoverflow.com/questions/17437016/ember-transition-rendering-complete-event) – Kingpin2k Jun 18 '14 at 22:27

1 Answers1

0

Alex,

I don't think you've told us enough about your "Flash Message". Where does this view live? Is it in the Application template or in your StoriesNew template?

The reason I ask is once you've initiated a transition, you should assume that your current view is no longer visible (it may not always be the case, but it's a safe assumption to make).

Here is a JSBin example of what you've described: http://emberjs.jsbin.com/yixuwamo/5

Wesley Workman
  • 917
  • 9
  • 22