<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>The Napkin ~ A Blog By Highgroove Studios comments on Faster Auto-Completion with Rails</title>
    <link>http://napkin.highgroove.com/</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>The Napkin ~ A Blog By Highgroove Studios comments</description>
    <item>
      <title>"Faster Auto-Completion with Rails": comment by Derek</title>
      <description>&lt;p&gt;Sam,&lt;/p&gt;


	&lt;ul&gt;
	&lt;li&gt;Put the file in your /lib directory. &lt;/li&gt;
		&lt;li&gt;I&amp;#8217;d call it &amp;#8220;local_autocomplete.rb&amp;#8221;...but the name shouldn&amp;#8217;t matter.&lt;/li&gt;
		&lt;li&gt;You don&amp;#8217;t need to require it&amp;#8230;Rails loads files in the /lib folder automatically.&lt;/li&gt;
	&lt;/ul&gt;</description>
      <pubDate>Wed, 21 Jun 2006 13:13:16 EST</pubDate>
      <guid>http://napkin.highgroove.com/articles/2006/06/15/snippet-faster-auto-completion-with-rails#comment-13</guid>
      <link>http://napkin.highgroove.com/articles/2006/06/15/snippet-faster-auto-completion-with-rails#comment-13</link>
    </item>
    <item>
      <title>"Faster Auto-Completion with Rails": comment by Sam</title>
      <description>Little bit more info if poss...

What do you call the file with the modules in and where do you place it (./lib ?) and does it need requiring..?</description>
      <pubDate>Tue, 20 Jun 2006 09:48:11 EST</pubDate>
      <guid>http://napkin.highgroove.com/articles/2006/06/15/snippet-faster-auto-completion-with-rails#comment-7</guid>
      <link>http://napkin.highgroove.com/articles/2006/06/15/snippet-faster-auto-completion-with-rails#comment-7</link>
    </item>
    <item>
      <title>"Faster Auto-Completion with Rails" by derek</title>
      <description>&lt;p&gt;Auto-Complete is a great tool when it provides possible results &lt;span class="caps"&gt;BEFORE&lt;/span&gt; you finish typing. Unfortunately, using &lt;a href="http://api.rubyonrails.com/classes/ActionView/Helpers/JavaScriptMacrosHelper.html#M000463"&gt;Rails&amp;#8217;s included &lt;span class="caps"&gt;AJAX&lt;/span&gt; helpers&lt;/a&gt; to query the database as you type often results in a large delay before matches are returned.&lt;/p&gt;


	&lt;p&gt;However, there is a lightning-quick option: pre-fetch the results in a Javascript array.&lt;/p&gt;


	&lt;p&gt;In a &lt;a href="http://www.highgroove.com"&gt;client project&lt;/a&gt;, users can add labels to events on their calendar. To prevent users from creating variations of the same label name (i.e. &amp;#8211; &amp;#8220;favorite&amp;#8221; vs. &amp;#8220;favorites&amp;#8221;), we needed to provide faster auto-complete functionality than that available through Rails&amp;#8217;s provided &lt;span class="caps"&gt;AJAX&lt;/span&gt; helpers.&lt;/p&gt;


	&lt;p&gt;We created a simple helper method for this case (special thanks to &lt;a href="http://www.chadfowler.com/"&gt;Chad Fowler&lt;/a&gt; and his &lt;a href="http://www.pragmaticprogrammer.com/titles/fr_rr/"&gt;&lt;em&gt;Rails Recipes&lt;/em&gt;&lt;/a&gt; book for the inspiration).&lt;/p&gt;


	&lt;p&gt;&lt;img src="/images/icons/download.png" alt="" /&gt; &lt;a href="/files/local_auto_complete.txt"&gt;Take a look at the &lt;em&gt;local_auto_complete_field&lt;/em&gt; helper method. &lt;span class="caps"&gt;TXT&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;


To call the function from your views:
&lt;pre&gt;
&amp;lt;%= local_auto_complete_field('name',@labels) %&amp;gt;
&lt;/pre&gt;

	&lt;p&gt;In the above example, we are adding JavaScript-powered auto-complete functionality to the &lt;code&gt;'name'&lt;/code&gt;  text field. The JavaScript array is generated by calling &lt;code&gt;#name&lt;/code&gt; on each element in the &lt;code&gt;@labels&lt;/code&gt; array. To override this behavior:&lt;/p&gt;


&lt;pre&gt;
&amp;lt;%= local_auto_complete_field('name',@labels, 
                              :method =&amp;gt; 'description') %&amp;gt;
&lt;/pre&gt;

	&lt;p&gt;Here&amp;#8217;s to faster auto-completion!&lt;/p&gt;

</description>
      <pubDate>Thu, 15 Jun 2006 15:18:00 EST</pubDate>
      <guid>&lt;a href="/articles/2006/06/15/snippet-faster-auto-completion-with-rails"&gt;Faster Auto-Completion with Rails&lt;/a&gt;</guid>
      <link>&lt;a href="/articles/2006/06/15/snippet-faster-auto-completion-with-rails"&gt;Faster Auto-Completion with Rails&lt;/a&gt;</link>
    </item>
  </channel>
</rss>
