<?xml version='1.0' encoding='utf-8' ?>
<rss version='2.0' xmlns:dc='http://purl.org/dc/elements/1.1/'>
  <channel>
    <title>Wolfmans Howlings: Flash problems with periodically_call_remote</title>
    <link>http://blog.wolfman.com/articles/2006/10/25/flash-problems-with-periodically_call_remote</link>
    <description>A programmers Blog about Ruby, Rails and a few other issue</description>
    <language>en-us</language>
    <ttl>40</ttl>
    <item>
      <title>Flash problems with periodically_call_remote</title>
      <description>
        &lt;p&gt;I just ran into this little problem which kept me scratching my head
        for quite a while. My flash message didn't show up on the next action.&lt;/p&gt;
        
        &lt;p&gt;I have a status page which polls a database for status using
        &lt;code&gt;periodically_call_remote&lt;/code&gt;, when the database reaches a certain state I
        show a button which says the process is complete go to next step.&lt;/p&gt;
        
        &lt;p&gt;The go to next step calls a controller action which does some processing
        that can take a few seconds, during that call any errors are
        dutifully written to flash like &lt;code&gt;flash[:error]= &quot;I got an error!&quot;&lt;/code&gt;
        then does a &lt;code&gt;redirect_to&lt;/code&gt; the listing page, where I expect to see the
        error flash at the top of the page.&lt;/p&gt;
        
        &lt;p&gt;This worked fine under development however under production on the
        production server I did not see those flash errors, so the user was
        like &quot;duh what happened??&quot;.&lt;/p&gt;
        
        &lt;p&gt;I could see the errors logged in the production log so I knew the
        flash was getting set, so what was happening????&lt;/p&gt;
        
        &lt;p&gt;Well to cut a long story short, while the controller was processing
        the next action (which can take a few seconds), the
        &lt;code&gt;periodically_call_remote&lt;/code&gt; can fire a few more times, this consumes
        the flash, so when it gets to the &lt;code&gt;redirect_to&lt;/code&gt; page the flash no longer
        shows up. In development mode the timing is different so the status
        page does not fire again before the listing page shows up so the flash
        is displayed. Did I mention I hate race conditions :)&lt;/p&gt;
        
        &lt;p&gt;The solution is trivial, stick a &lt;code&gt;flash.keep&lt;/code&gt; in the action that is
        called by the &lt;code&gt;periodically_call_remote&lt;/code&gt;, and the flash is preserved
        for the &lt;code&gt;redirect_to&lt;/code&gt; action. Problem solved!&lt;/p&gt;
        
        &lt;p&gt;&lt;a href=&quot;http://technorati.com/tag/flash+periodically_call_remote&quot; rel=&quot;tag&quot;&gt;&lt;/a&gt;
        &lt;a href=&quot;http://technorati.com/tag/rails+flash&quot; rel=&quot;tag&quot;&gt;&lt;/a&gt;&lt;/p&gt;
      </description>
      <author>Jim Morris</author>
      <pubDate>Wed, 25 Oct 2006 14:08:38 -0700</pubDate>
      <link>http://blog.wolfman.com/articles/2006/10/25/flash-problems-with-periodically_call_remote</link>
      <guid isPermaLink='false'>urn:uuid:d0a3ed6d-293f-4347-8676-b57ce5891aac</guid>
    </item>
  </channel>
</rss>
