title: Rails doesn't display flash messages after ajax call
body: <p>I'm writing a rails 4.0.2 app, and am trying to get a Flash notice to display in my view after an AJAX event.</p>
  
  <p>In my view I display a calendar with days a user can click on.  When they do so, I fire an AJAX event via an onclick event handler which updates my model, either adding or removing a record.  After firing the event, I complete a page refresh in order to display the updated results.</p>
  
  <p>I found I had to do a page refresh during the JS click event in order to get the view to update properly.  A redirect or render in the controller alone wasn't enough.</p>
  
  <p>So, to that effect, I have set a Flash notice in my controller...</p>
  
  <pre><code>def set_conflicts
    @conflict = @member.conflicts.for_date(params[:date]).first
  
    if @conflict
      @conflict.destroy
    else
      conflict_date = Date.parse(params[:date])
      unless Conflict.create(
          month: conflict_date.month,
          day:   conflict_date.day,
          year:  conflict_date.year,
          member: @member
      )
        flash[:alert] = 'Oops, there was a problem updating conflicts'
      end
    end
    flash[:notice] = 'This is a test!'
    redirect_to manage_member_conflicts_path(@member)
  end
  </code></pre>
  
  <p>... and have included the following flash display logic in my <strong>application.haml</strong>...</p>
  
  <pre><code>...
  %body
    = p flash.inspect
    - flash.each do |type, message|
      = content_tag(:div, message, :class =&gt; "flash-#{type}")
  
    = render 'devise/menu/login_items'
    = yield
  </code></pre>
  
  <p><em>Note: I use HAML instead of ERB in my views</em></p>
  
  <p>Yet, no matter what I try, the Flash message does not display.  Everything else works as expected <em>except</em> the <strong><em>flash message</em></strong>, and I haven't been able to figure out <em>why</em>.</p>
  
  <p>I suspect it's got something to do with the AJAX refresh I'm doing combined with the redirect (and maybe even turbolinks) but I've looked through other answers here on SO and simply can't get it to work.  Clearly, I'm missing something.</p>
  
  <p>Here's the JS click handler (it's pretty simple):</p>
  
  <pre><code>window.calendarClick = (eventDate, linkURL) -&gt;
    event = $(document.getElementById(eventDate))
    event.toggleClass('selected')
  
    # Set or Remove conflicts
    $.ajax
      url: linkURL
      data:
        date: eventDate
  
    # Refresh the page
    $.ajax
      url: '',
      context: document.body,
      success: (s,x) -&gt;
        $(this).html(s)
  </code></pre>