Topic: AJAX and "flash"-like messages?

I'm using some AJAX to create a form, and when the form is saved, I want to give the user some information.  I have a flash area in my layout, and I'd like to use this same area if at all possible.  I know I could have an html tag somewhere and use RJS to display a message, but does anyone know if there's a way to combine the flash items and an AJAX form? 

I was also thinking about possibly combining the flash layout and the AJAX informational messages into one area like this:

<% if @msg %><div id="notice"><%= @msg %></div>
<% else %>
  <% if flash[:notice] %><div id="notice"><%= flash[:notice] %></div>
<% end %>

That way, if I'm using AJAX to set the @msg to something, it won't use the flash items; but then, the flash items will use the location when the @msg doesn't exist.  Does anyone see any obvious problems with this, or know of a better way of implementing it?  Thanks for any insight or help.

Re: AJAX and "flash"-like messages?

That stuff with @message won't really work as the ruby code is lost once the view is rendered. Or will you re-render the view through AJAX? i think you are looking for something like this:

<div id="notice" <%= 'style="display:none;"' unless flash[:notice]%> >
  <%= flash[:notice] %>

flash[:notice]= "blabla"

# RJS:
page["notice"].replace_html flash[:notice]

That way, a flash notice will be shown no matter weither you render the complete view in a normal page request or use AJAX to update the page...

Re: AJAX and "flash"-like messages?

Ah, I see.  Yah, I wasn't thinking about that.  Thanks Duplex, that should probably solve my problem.