<?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>Musings of a Trained Monkey: Typo Administration: article tagging II...</title>
    <link>http://www.stevelongdo.com/articles/2006/03/08/typo-administration-article-tagging-ii</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description></description>
    <item>
      <title>Typo Administration: article tagging II...</title>
      <description>Let's go through the the steps I have taken so far to add auto completion of the tagging capabilities of &lt;a href="http://typosphere.org"&gt;Typo&lt;/a&gt;.  

&lt;ol&gt;
&lt;li&gt;Checked out a fresh copy of the trunk from svn://typosphere.org/typo/trunk &lt;/li&gt;
&lt;li&gt;Ran it against my backup database of this site.&lt;/li&gt;
&lt;li&gt;Fired up &lt;a href="http://www.macromates.com"&gt;TextMate&lt;/a&gt; and started to work!&lt;/li&gt;

&lt;/ol&gt;
I made a decision right off to not use &lt;a href="http://www.adaptivepath.com/publications/essays/archives/000385.php"&gt;AJAX&lt;/a&gt; for this.  Building the entire list of tags in use for an individual user's blog shouldn't be too much overhead to send down the wire once, versus pinging the server each time a key is typed. &lt;cite&gt;(Although &lt;a href="http://typosphere.org"&gt;Typo&lt;/a&gt; foils my effort to reduce roundtrips to the server, because live preview of Articles monitors the whole Article form not just the Title and Body fields...)&lt;/cite&gt;
I am sticking by my decision for now, if we want to add &lt;a href="http://del.icio.us"&gt;del.icio.us&lt;/a&gt;, &lt;a href="http://technorati.com/"&gt;technorati&lt;/a&gt; or even &lt;a href="http://ma.gnolia.com/"&gt;ma.gnolia.com&lt;/a&gt; tags in the future then &lt;a href="http://www.adaptivepath.com/publications/essays/archives/000385.php"&gt;AJAX&lt;/a&gt; will come back into the picture.  For now we will &lt;strong&gt;K&lt;/strong&gt;eep &lt;strong&gt;I&lt;/strong&gt;t &lt;strong&gt;S&lt;/strong&gt;imple &lt;strong&gt;S&lt;/strong&gt;...teve :-)&lt;br /&gt;

First off we will need to get the Tags down to the view code. So off to the admin controller code's new and edit methods to get our Tags included:&lt;pre style="overflow: auto"&gt;&lt;div class="typocode"&gt;&lt;div class="codetitle"&gt;app/controllers/admin/content_controller.rb&lt;/div&gt;&lt;pre&gt;&lt;code class="typocode_ruby "&gt;&lt;span class="keyword"&gt;def &lt;/span&gt;&lt;span class="method"&gt;new&lt;/span&gt;
&lt;span class="punct"&gt;...&lt;/span&gt;
    &lt;span class="attribute"&gt;@categories&lt;/span&gt; &lt;span class="punct"&gt;=&lt;/span&gt; &lt;span class="constant"&gt;Category&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;find&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="symbol"&gt;:all&lt;/span&gt;&lt;span class="punct"&gt;,&lt;/span&gt; &lt;span class="symbol"&gt;:order&lt;/span&gt; &lt;span class="punct"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="punct"&gt;'&lt;/span&gt;&lt;span class="string"&gt;UPPER(name)&lt;/span&gt;&lt;span class="punct"&gt;')&lt;/span&gt;

    &lt;span class="attribute"&gt;@tags&lt;/span&gt; &lt;span class="punct"&gt;=&lt;/span&gt; &lt;span class="constant"&gt;Tag&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;find_all_with_article_counters&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="number"&gt;666&lt;/span&gt;&lt;span class="punct"&gt;)&lt;/span&gt;
&lt;span class="punct"&gt;...&lt;/span&gt;
&lt;span class="keyword"&gt;end&lt;/span&gt;

&lt;span class="keyword"&gt;def &lt;/span&gt;&lt;span class="method"&gt;edit&lt;/span&gt;
&lt;span class="punct"&gt;...&lt;/span&gt;
    &lt;span class="attribute"&gt;@selected&lt;/span&gt; &lt;span class="punct"&gt;=&lt;/span&gt; &lt;span class="attribute"&gt;@article&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;categories&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;collect&lt;/span&gt; &lt;span class="punct"&gt;{&lt;/span&gt; &lt;span class="punct"&gt;|&lt;/span&gt;&lt;span class="ident"&gt;cat&lt;/span&gt;&lt;span class="punct"&gt;|&lt;/span&gt; &lt;span class="ident"&gt;cat&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;id&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;to_i&lt;/span&gt; &lt;span class="punct"&gt;}&lt;/span&gt;

    &lt;span class="attribute"&gt;@tags&lt;/span&gt; &lt;span class="punct"&gt;=&lt;/span&gt; &lt;span class="constant"&gt;Tag&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;find_all_with_article_counters&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="number"&gt;666&lt;/span&gt;&lt;span class="punct"&gt;)&lt;/span&gt;
    
    &lt;span class="keyword"&gt;if&lt;/span&gt; &lt;span class="ident"&gt;request&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;post?&lt;/span&gt; 

&lt;span class="punct"&gt;...&lt;/span&gt;
&lt;span class="keyword"&gt;end&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/pre&gt;
The &lt;code class="typocode_ruby"&gt;&lt;span class="attribute"&gt;@tags&lt;/span&gt; &lt;span class="punct"&gt;=&lt;/span&gt; &lt;span class="constant"&gt;Tag&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;find_all_with_article_counters&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="number"&gt;666&lt;/span&gt;&lt;span class="punct"&gt;)&lt;/span&gt;&lt;/code&gt; is how we are accomplishing this. I could just get all the Tags with &lt;code class="typocode_ruby "&gt;&lt;span class="constant"&gt;Tag&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;find&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="symbol"&gt;:all&lt;/span&gt;&lt;span class="punct"&gt;)&lt;/span&gt;&lt;/code&gt; but this little bit of premature optimization will come in handy if we want to show a count of how many articles are already tagged with a given tag. We can also limit our search to less than 666 records. I just like to tag things a lot.

&lt;br /&gt;&lt;br /&gt;
I will post the next part later today as this post is getting a bit longish.</description>
      <pubDate>Wed, 08 Mar 2006 23:31:00 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:57f9832d-7f72-45a8-8127-77f39e7df089</guid>
      <author>Steve Longdo</author>
      <link>http://www.stevelongdo.com/articles/2006/03/08/typo-administration-article-tagging-ii</link>
      <category>ajax</category>
      <category>javascript</category>
      <category>tag</category>
      <category>typo</category>
      <category>ruby</category>
      <category>rails</category>
      <trackback:ping>http://www.stevelongdo.com/articles/trackback/95</trackback:ping>
    </item>
  </channel>
</rss>
