<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="/stylesheets/rss.css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <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>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>A programmers Blog about Ruby, Rails and a few other issues</description>
    <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]= "I got an error!"&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 "duh what happened??".&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="http://technorati.com/tag/flash+periodically_call_remote" rel="tag"&gt;&lt;/a&gt;
&lt;a href="http://technorati.com/tag/rails+flash" rel="tag"&gt;&lt;/a&gt;&lt;/p&gt;</description>
      <pubDate>Wed, 25 Oct 2006 14:08:38 -0700</pubDate>
      <guid isPermaLink="false">urn:uuid:d0a3ed6d-293f-4347-8676-b57ce5891aac</guid>
      <author>Jim Morris</author>
      <link>http://blog.wolfman.com/articles/2006/10/25/flash-problems-with-periodically_call_remote</link>
      <category>Rails</category>
      <category>rails</category>
      <category>flash</category>
      <category>periodically_call_remote</category>
      <trackback:ping>http://blog.wolfman.com/articles/trackback/64</trackback:ping>
    </item>
  </channel>
</rss>
