<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>SciWerks.com &#187; plugins</title>
	<atom:link href="http://www.sciwerks.com/blog/category/ruby-on-rails/plugins/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.sciwerks.com/blog</link>
	<description>Software for scientists, by scientists</description>
	<lastBuildDate>Fri, 24 Oct 2008 01:02:08 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Double Submit Protection</title>
		<link>http://www.sciwerks.com/blog/2006/10/23/double-submit-protection/</link>
		<comments>http://www.sciwerks.com/blog/2006/10/23/double-submit-protection/#comments</comments>
		<pubDate>Mon, 23 Oct 2006 04:31:28 +0000</pubDate>
		<dc:creator>Kevin Olbrich</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[plugins]]></category>

		<guid isPermaLink="false">http://www.sciwerks.com/blog/2006/10/23/double-submit-protection/</guid>
		<description><![CDATA[The ease with which a user can inadvertently or deliberately submit a web form multiple times is a persistent problem with web applications and web forms.

Typically this problem arises when a user attempts to submit a form and the server does not immediately respond to the request. The delay can be due to network traffic, high load, or a particularly complex action that must be completed. In any event, it does not take long before the user begins to wonder if they actually hit the button and they click it again just to make sure.

If your application is not properly designed, this can lead to multiple identical records, or actions being processed more than once. Sometimes with undesirable side effects (like multiple billing).]]></description>
			<content:encoded><![CDATA[<p>The ease with which a user can inadvertently or deliberately submit a web form multiple times is a persistent problem with web applications and web forms.</p>
<p>Typically this problem arises when a user attempts to submit a form and the server does not immediately respond to the request.  The delay can be due to network traffic, high load, or a particularly complex action that must be completed.  In any event, it does not take long before the user begins to wonder if they actually hit the button and they click it again just to make sure.</p>
<p>If your application is not properly designed, this can lead to multiple identical records, or actions being processed more than once.  Sometimes with undesirable side effects (like multiple billing).</p>
<p>There are a couple of solutions to this problem.</p>
<ol>
<li>Warn the user to avoid clicking the button more than once&#8230;. this is a complete cop out on the part of the programmers and is just inviting trouble.
</li>
<li>Disable the submit button when pressed (using AJAX).  This sort of works, but if the server is slow and non-responsive, this is likely to fail too.  This will also fail if the user has JS turned off, or if they reload or go back to the form and resubmit.</li>
<li>Disable the button via javascript.  This works reasonably well, but if the user uses the browser back button, they can press the submit button again, resulting in a double submit.  Again, this will fail if JS is turned off</li>
</ol>
<p>The reality is that all of these solutions have problems and don&#8217;t really address the underlying issue.  The real problem is not that the user is submitting multiple copies of the same request, the problem is that the server is trying to act on all of them.</p>
<p><script type="text/javascript"><!--
google_ad_client = "pub-1072568092760209";
google_ad_width = 468;
google_ad_height = 60;
google_ad_format = "468x60_as";
google_ad_type = "text_image";
google_ad_channel = "";
//--></script>
<script type="text/javascript"
  src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>
<h2>The double_submit_protection plugin for Rails</h2>
<h3>How it works.</h3>
<ol>
<li> User submits a request</li>
<li>If the request is successfully processed, it records the time and the contents of the params
</li>
<li>if a request with an identical params array is processed within a predefined interval it will reject the request or redirect to another page
</li>
</ol>
<p>The user can then do whatever they want and they won&#8217;t be able to send the identical request again until the time interval expires.</p>
<p>If they change the content of the form and resubmit, that request will work.</p>
<h3>Installation</h3>
<div class="codesnip-container" >script/plugin install svn://sciwerks.com/home/sciwerks/public_svn/double_submit_protection/</div>
<h3>Usage:</h3>
<p>First, restart your server.</p>
<p>To protect your entire application from duplicate post requests (non-ajax) you can put the following code in your application controller.</p>
<div class="codesnip-container" >
<div class="codesnip" style="font-family: monospace;">
<ol>
<li class="li1">
<div class="de1"><span class="co1">## application.rb</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">double_submit_protection&nbsp; :method=&gt;:post,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;:xhr =&gt; <span class="kw2">false</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;:interval =&gt; <span class="nu0">60</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;:flash =&gt; <span class="br0">&#123;</span>:warning =&gt; &#8216;Double Submit Detected&#8217;<span class="br0">&#125;</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;:redirect_to =&gt; <span class="br0">&#123;</span>:action=&gt;&#8217;index&#8217;<span class="br0">&#125;</span> </div>
</li>
</ol>
</div>
</div>
<h3>Disclaimer and Tips</h3>
<p>This is beta stuff, so don&#8217;t be surprised if it breaks things.  In particular, it can block some repeated AJAX calls if you don&#8217;t configure it properly.</p>
<p>Note that since it uses a before filter to do it&#8217;s dirty work, you can limit the actions it applies to by passing an parameters like</p>
<div class="codesnip-container" >:only=>['action'], or<br />
:except=>['action']</div>
<p>You may need to adjust the timeout period to suit your needs.  Longer timeouts will make your session object get pretty big.</p>
<p>If you have a datetime_select in your form, it may circumvent any timeout interval.  If this control defaults to the current time, then the plugin will not be able to tell that it is the same because the &#8216;minutes&#8217; field will be changing.  It should work fine against multiple submit presses, but it will have a harder time with refresh-submit cases.  Future versions may have the option to ignore datetimes in the params.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.sciwerks.com/blog/2006/10/23/double-submit-protection/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Auto disabling the submit button with KRJS</title>
		<link>http://www.sciwerks.com/blog/2006/10/04/auto-disabling-the-submit-button-with-krjs/</link>
		<comments>http://www.sciwerks.com/blog/2006/10/04/auto-disabling-the-submit-button-with-krjs/#comments</comments>
		<pubDate>Thu, 05 Oct 2006 00:52:49 +0000</pubDate>
		<dc:creator>Kevin Olbrich</dc:creator>
				<category><![CDATA[AJAX]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[User Interface]]></category>
		<category><![CDATA[plugins]]></category>

		<guid isPermaLink="false">http://www.sciwerks.com/blog/2006/10/04/auto-disabling-the-submit-button-with-krjs/</guid>
		<description><![CDATA[Benjamin over at RubyOnRailsBlog   was recently wondering about how to painlessly disable a submit button to prevent the user from hitting it multiple times.
This requires some sort of javascript hackery to achieve, but the easiest way I&#8217;ve found to do this is with my trusty old KRJS pocketknife.




# in application controller


&#160;


def on_commit_click


&#160; render [...]]]></description>
			<content:encoded><![CDATA[<p>Benjamin over at <a href="http://www.rubyonrailsblog.com/articles/2006/10/03/disable-submit-button-after-its-pressed">RubyOnRailsBlog</a>   was recently wondering about how to painlessly disable a submit button to prevent the user from hitting it multiple times.</p>
<p>This requires some sort of javascript hackery to achieve, but the easiest way I&#8217;ve found to do this is with my trusty old KRJS pocketknife.</p>
<div class="codesnip-container" >
<div class="codesnip" style="font-family: monospace;">
<ol>
<li class="li1">
<div class="de1"><span class="co1"># in application controller</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">def</span> on_commit_click</div>
</li>
<li class="li1">
<div class="de1">&nbsp; render :update |page| <span class="kw1">do</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;page<span class="br0">&#91;</span>&#8216;commit&#8217;<span class="br0">&#93;</span>.<span class="me1">disabled</span> = <span class="kw2">true</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;page &lt;&lt; <span class="st0">&quot;$(&#8217;commit&#8217;).form.submit();&quot;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw1">end</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">end</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="co1"># in the form</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&lt;%= submit_tag &#8216;Submit&#8217;, :id=&gt;&#8217;commit&#8217; %&gt; </div>
</li>
</ol>
</div>
</div>
<p>This will add this behavior for all submit buttons with the &#8216;commit&#8217; id.  The hardest part here is remembering to add the &#8216;commit&#8217; id.</p>
<p>Requires: <a href="http://www.agilewebdevelopment.com/plugins/krjs">KRJS Plugin </a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.sciwerks.com/blog/2006/10/04/auto-disabling-the-submit-button-with-krjs/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>multiple_auto_complete plugin</title>
		<link>http://www.sciwerks.com/blog/2006/09/25/multiple_auto_complete_plugin/</link>
		<comments>http://www.sciwerks.com/blog/2006/09/25/multiple_auto_complete_plugin/#comments</comments>
		<pubDate>Mon, 25 Sep 2006 17:59:45 +0000</pubDate>
		<dc:creator>Kevin Olbrich</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[User Interface]]></category>
		<category><![CDATA[auto_complete]]></category>
		<category><![CDATA[plugins]]></category>

		<guid isPermaLink="false">http://www.sciwerks.com/blog/2006/09/25/16/</guid>
		<description><![CDATA[Rails&#8217; auto_complete control can be a really handy way to allow users to select an object or string from a list of pre-existing values, however, one big limitation to its use is the fact that you can&#8217;t have more than one of them on a single page.  
UPDATE: just to clarify this a bit. [...]]]></description>
			<content:encoded><![CDATA[<p>Rails&#8217; auto_complete control can be a really handy way to allow users to select an object or string from a list of pre-existing values, however, one big limitation to its use is the fact that you can&#8217;t have more than one of them on a single page.  </p>
<p>UPDATE: just to clarify this a bit.  If you have more than one auto_complete that tries to access the same model/field combo, you get into trouble.  You can have multiple auto_completes so long as they access different model/field combinations.</p>
<p>I tried a couple of hacks around this problem (some involving method_missing), and finally found a method that works pretty well and doesn&#8217;t mess up your controllers.</p>
<p>The approach I ended up using was to rewrite the &#8216;auto_complete_for&#8217; and &#8216;text_field_with_auto_complete&#8217; functions so that they ignore trailing numbers on a dom_id. Once you install the plugin (see below), you simply use it like this&#8230;</p>
<div class="codesnip-container" >
<div class="codesnip" style="font-family: monospace;">
<ol>
<li class="li1">
<div class="de1"><span class="co1"># View file</span></div>
</li>
<li class="li1">
<div class="de1">&lt;%= text_field_with_auto_complete &#8216;object_1&#8242;, &#8216;name&#8217; %&gt;</div>
</li>
<li class="li1">
<div class="de1">&lt;%= text_field_with_auto_complete &#8216;object_2&#8242;, &#8216;name&#8217; %&gt; </div>
</li>
</ol>
</div>
</div>
<p></p>
<div class="codesnip-container" >
<div class="codesnip" style="font-family: monospace;">
<ol>
<li class="li1">
<div class="de1"><span class="co1"># controller file</span></div>
</li>
<li class="li1">
<div class="de1">auto_complete_for :object, :name </div>
</li>
</ol>
</div>
</div>
<p>All the auto_complete fields named /object[-_]d+/ will call the &#8216;auto_complete_for_object_name&#8217; function in the controller now.  The default response function will pull out the correct information and respond as usual.</p>
<p>When you submit the form, the values will be passed in the params hash as </p>
<div class="codesnip-container" >
<div class="codesnip" style="font-family: monospace;">
<ol>
<li class="li1">
<div class="de1">params = <span class="br0">&#123;</span> &#8216;object_1&#8242; =&gt; <span class="br0">&#123;</span>&#8216;name&#8217;=&gt;&#8217;name1&#8242;<span class="br0">&#125;</span>, &#8216;object_2&#8242;=&gt;<span class="br0">&#123;</span>&#8216;name&#8217;=&gt;&#8217;name2&#8242; <span class="br0">&#125;</span><span class="br0">&#125;</span> </div>
</li>
</ol>
</div>
</div>
<h3>Installation</h3>
<div class="codesnip-container" >script/plugin install svn://sciwerks.com/home/sciwerks/public_svn/multiple_auto_complete/</div>
]]></content:encoded>
			<wfw:commentRss>http://www.sciwerks.com/blog/2006/09/25/multiple_auto_complete_plugin/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>
