2

I have a weird problem with flash messages not showing up in IE (tried 8 and 9):

  • it always works with other browser
  • the problem is only on one page (this page renders different forms based on a parameter)
  • the flash message always appears on development, but only sometimes on staging and prod
  • I see the flash message being logged in all cases, [notice] Your changes have been saved. Next step..., even when it doesn't appear on the page!
  • The error flash message always shows up, it's the notice that doesn't work properly.

Here's my update action:

def update 
  @form = Forms::Events::EditForm.build_for(@event, params[:event])
  if @form.save
    redirect_to edit_challenge_path(@form.event, form: @form.event_name), notice: "Your changes have been saved. #{@form.next_form}".html_safe
  else
    flash.now[:alert] = "Please correct the errors highlighted below."
    render "groups/events/edit"
  end
end

Any ideas on what could be wrong?

Robin
  • 21,667
  • 10
  • 62
  • 85

1 Answers1

2

Agreeing with @AnthonyAlberto's comment. What you want is the .now method of flash, e.g. flash.now[:alert] = ... Here's a good explanation of the difference.

Tom Harrison
  • 13,533
  • 3
  • 49
  • 77
  • Thanks. You're right that I should use `.now` in this case. But this one's working all the time. It's the success flash message that isn't working consistantly... – Robin Nov 28 '12 at 23:09
  • Oh. Hrrm. Normally I would just bash IE and so on, but this really doesn't have anything to do with the browser -- it's simple HTML rails renders and should just work. Have you done `view source` -- maybe it's just not showing up due to some CSS issue ... in which case I could indeed bash IE :-) – Tom Harrison Nov 28 '12 at 23:15
  • Sadly no, it's not just CSS, the flash is just not there. And I don't know whose fault it is, but it's definitely related to IE in some way, because it works 100% of the time in other browsers... It's in a very used part of the site, so I'm sure about that. – Robin Nov 29 '12 at 02:12
  • Rats! OK, then some debugging is in order. The flash is just an object, and you should [read about it here if you haven't already](http://guides.rubyonrails.org/action_controller_overview.html#the-flash). It uses the session, which is a special form of cookie that the browser is responsible for managing, with [methods documented here](http://api.rubyonrails.org/classes/ActionDispatch/Flash/FlashHash.html). So you should be able to inspect it at a given point in time, e.g. `logger.debug "Flash contains #{flash.inspect}"` or call other methods. – Tom Harrison Nov 29 '12 at 02:24
  • I added debugging messages: update action -> form saved properly -> redirection to edit action with notice set -> edit action -> render edit view. On all browsers, on the edit action, the flash is set. On ie8, it's not. I checked the config, the session store is :cookie_store, with key: "_cp_session". I checked the size of this cookie, and it's less than 1ko. So it's nowhere near the limit (which I thought could be the problem...). I've no idea what's going on. Thanks for your help anyways. – Robin Nov 29 '12 at 17:23
  • Accepting this answer for now. – Robin Jan 13 '13 at 04:44
  • I am having a similar problem (rails 3.1.x) and just wanted to add a comment. I added logger.debug lines that log the value of `flash[:alert]` because after redirects flash wasn't working on our staging server, but it was working in development. The result was that adding the debug lines broke flash in development too! Not sure what is going on here. Flash is weird... –  Oct 27 '15 at 08:48