<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="/stylesheets/rss.css" type="text/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>I.NFECTIO.US: Rails acts_as_threaded Plugin</title>
    <link>http://i.nfectio.us/articles/2006/02/05/rails-acts_as_threaded-plugin</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>"Nothing in life is worth doing if you have no life while doing it"</description>
    <item>
      <title>Rails acts_as_threaded Plugin</title>
      <description>&lt;p&gt;While tinkering around with the acts_as_nested_set act of ActiveRecord, I tried to build a threaded forum with it. I ran into some difficulties in that a nested_set is designed to only have one root. Obviously, in a threaded forum, each thread would be its own root. So after wasting a couple hours trying to make nested_set work, I decided to use what I consider to be the best part of Rails: &lt;em&gt;plugins&lt;/em&gt;. "&lt;strong&gt;acts_as_threaded&lt;/strong&gt;" was born 1 hour later.
&lt;/p&gt;
&lt;br /&gt;&lt;p&gt;While I used it to build a threaded forum in this demo, it's design was inspired by a different project at work. The acts_as_tree behavior could have worked, but I needed a better way of containing my children (much like in real life).&lt;/p&gt;

&lt;br /&gt;
&lt;p&gt;I've included an 11 minute screencast of building an ugly looking Threaded Forum, but the concepts are there. I can still remember spending many man hours with my programming team at &lt;a href="http://www.bravenet.com/"&gt;Bravenet&lt;/a&gt; to design and build the forum product we offered there. If Rails existed back then, we could have built it in a day. (Leave me a comment on how the screencast turned out.)&lt;/p&gt;
&lt;br /&gt;
&lt;p&gt;
Click the image to view the screencast of acts_as_threaded in use: (8 MB)&lt;/p&gt;&lt;br /&gt;
&lt;a href="/plugins/acts_as_threaded/threaded.swf"&gt;&lt;img src="/images/acts_as_threaded.gif" border="0" /&gt;&lt;/a&gt;

&lt;br /&gt;&lt;br /&gt;
&lt;p&gt;As usual, you can download the plugin &lt;a href="/plugins/acts_as_threaded.zip"&gt;here&lt;/a&gt;. I will submit it as a patch when I solidify it and create the tests.&lt;/p&gt;
&lt;p&gt;
If you are following the tutorial, here is the display code in full.&lt;/p&gt;
&lt;div style="margin:10px;border: 1px solid #8DBA47; width:500px; height:250px; overflow:scroll; background-color: #F1F8E4;"&gt;

&lt;pre&gt;
def display_threads(threads)
    content = ''
    for thread in threads
      content &lt;&lt; content_tag('div',
                  content_tag('div',"* " + link_to("#{h thread.title}", {:action =&gt; 'show', :id =&gt; thread.id}, {'style' =&gt; 'color: #00f'}) + " " +
                  content_tag('span', " by #{h thread.name} &amp;middot; #{thread.created_at.strftime('%b, %d %Y - %I:%M %p')}", 'style' =&gt; 'font:10px tahoma;color:#666;')),
                  'style' =&gt; "margin:5px 0px;padding-left:#{thread.depth*20}")
    end
    content
  end
&lt;/pre&gt;&lt;/div&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;B&gt;UPDATE: &lt;a href="http://www.railtie.net/articles/2006/03/31/implement-acts_as_threaded-without-a-plugin"&gt;See how to do this without a plugin using native Rails functionality.&lt;/a&gt;</description>
      <pubDate>Sun, 05 Feb 2006 17:15:00 -0800</pubDate>
      <guid isPermaLink="false">urn:uuid:7fba5a892cea7fe2970d12b3ee49a6f3</guid>
      <author>Bob Silva</author>
      <link>http://i.nfectio.us/articles/2006/02/05/rails-acts_as_threaded-plugin</link>
      <category>Ruby on Rails</category>
    </item>
    <item>
      <title>"Rails acts_as_threaded Plugin" by jaldrich@digiglyph.com</title>
      <description>Hello,
I'm using this plugin for a couple different models, but have found that the left and right edge values are not updated correctly when adding threads in a depth-first fashion. In my case I am creating a new thread by copying an existing one (creating a document from a template). I'm wondering if someone could provide feedback on the best way to copy a thread and avoid the problem of the incorrect edge values.
Thanks,
Jeff</description>
      <pubDate>Tue, 09 Jan 2007 08:23:26 -0800</pubDate>
      <guid isPermaLink="false">urn:uuid:b1855f4d-cb16-4288-9a7c-575c67174b0d</guid>
      <link>http://i.nfectio.us/articles/2006/02/05/rails-acts_as_threaded-plugin#comment-244</link>
    </item>
    <item>
      <title>"Rails acts_as_threaded Plugin" by Drew Noakes</title>
      <description>You may like to try this plugin:

&lt;a href="http://wiki.rubyonrails.org/rails/pages/BetterNestedSet" rel="nofollow"&gt;http://wiki.rubyonrails.org/rails/pages/BetterNestedSet&lt;/a&gt;</description>
      <pubDate>Wed, 20 Dec 2006 08:49:56 -0800</pubDate>
      <guid isPermaLink="false">urn:uuid:f403f175-fc21-4467-b9f2-84c76e2253de</guid>
      <link>http://i.nfectio.us/articles/2006/02/05/rails-acts_as_threaded-plugin#comment-238</link>
    </item>
    <item>
      <title>"Rails acts_as_threaded Plugin" by Johnson Pet</title>
      <description>Nice plugin

- Out of topic: What software did you use to create the screencast?</description>
      <pubDate>Sun, 29 Oct 2006 07:13:38 -0800</pubDate>
      <guid isPermaLink="false">urn:uuid:99bb6e5b-c421-49a8-980e-ece366df9a35</guid>
      <link>http://i.nfectio.us/articles/2006/02/05/rails-acts_as_threaded-plugin#comment-208</link>
    </item>
    <item>
      <title>"Rails acts_as_threaded Plugin" by Trevor Turk</title>
      <description>Sweet deal. You worked at Bravenet? Man, just hearing that name brings back so many memories. I used your tools on a bunch of my sites :)</description>
      <pubDate>Sun, 22 Oct 2006 21:20:32 -0700</pubDate>
      <guid isPermaLink="false">urn:uuid:0d2ad8e3-2c82-4958-8094-359f24014fdc</guid>
      <link>http://i.nfectio.us/articles/2006/02/05/rails-acts_as_threaded-plugin#comment-193</link>
    </item>
    <item>
      <title>"Rails acts_as_threaded Plugin" by Bob Silva</title>
      <description>Glad to hear that praxedis, be sure to look at the article here that shows how to accomplish the same thing without my plugin. Using the scope operator and a few callbacks can achieve the same results using only acts_as_nested_set which in my opinion is always the best route.</description>
      <pubDate>Wed, 04 Oct 2006 21:42:44 -0700</pubDate>
      <guid isPermaLink="false">urn:uuid:a03cadf3-b6fe-4b16-8b66-8e6463dafd90</guid>
      <link>http://i.nfectio.us/articles/2006/02/05/rails-acts_as_threaded-plugin#comment-175</link>
    </item>
    <item>
      <title>"Rails acts_as_threaded Plugin" by praxedis</title>
      <description>Hey, Bob. Just wanted to say thanks for the plugin and give you my example for it. Just launched this week. Needs to be extended a little more, but you'll get the idea.

&lt;a href="http://forum.neoaztlan.com" rel="nofollow"&gt;http://forum.neoaztlan.com&lt;/a&gt;</description>
      <pubDate>Wed, 04 Oct 2006 11:41:26 -0700</pubDate>
      <guid isPermaLink="false">urn:uuid:67955ad0-da41-4dec-98d9-57113f3c17bb</guid>
      <link>http://i.nfectio.us/articles/2006/02/05/rails-acts_as_threaded-plugin#comment-173</link>
    </item>
    <item>
      <title>"Rails acts_as_threaded Plugin" by Bob Silva</title>
      <description>Philip,

Depends on what you are trying to accomplish. You can accomplish a threaded relationship with both components, one is read heavy and one is write heavy (acts_as_tree and acts_as_nested_set, respectively. I prefer the acts_as_nested_set for my uses. With that said, I've extracted it out into a plugin and applied some of the existing patches (as well as a few of my own) to the implementation. Core will eventually yank acts_as_nested_set out into a plugin along with the others I imagine, so I'm not worried about support which I assume is one of the reasons Rich is suggesting to use the tree format.</description>
      <pubDate>Wed, 30 Aug 2006 15:28:22 -0700</pubDate>
      <guid isPermaLink="false">urn:uuid:47b639bf-bbc5-4e72-9da0-1ca50b3ebd70</guid>
      <link>http://i.nfectio.us/articles/2006/02/05/rails-acts_as_threaded-plugin#comment-65</link>
    </item>
    <item>
      <title>"Rails acts_as_threaded Plugin" by philip tsai</title>
      <description>
 Is Rich's comment correct?  How would you compare performance and features between the two?</description>
      <pubDate>Tue, 29 Aug 2006 16:52:50 -0700</pubDate>
      <guid isPermaLink="false">urn:uuid:7221efbf-e1ee-4b92-afbf-439c0d94f7a5</guid>
      <link>http://i.nfectio.us/articles/2006/02/05/rails-acts_as_threaded-plugin#comment-64</link>
    </item>
    <item>
      <title>"Rails acts_as_threaded Plugin" by Rich Collins</title>
      <description>You shouldn't use acts_as_nested_set you should use acts_as_tree with recursively cascaded eager loading</description>
      <pubDate>Fri, 18 Aug 2006 22:02:55 -0700</pubDate>
      <guid isPermaLink="false">urn:uuid:307070ad-51fa-439b-a397-d7ece2806c1b</guid>
      <link>http://i.nfectio.us/articles/2006/02/05/rails-acts_as_threaded-plugin#comment-56</link>
    </item>
    <item>
      <title>"Rails acts_as_threaded Plugin" by Bob Silva</title>
      <description>As Steve said, refer to this post about using acts_as_nested_set to acheive the same functionality without the plugin.
&lt;br /&gt;
&lt;a href="http://www.railtie.net/articles/2006/03/31/implement-acts_as_threaded-without-a-plugin" rel="nofollow"&gt;http://www.railtie.net/articles/2006/03/31/implement-acts_as_threaded-without-a-plugin&lt;/a&gt;</description>
      <pubDate>Wed, 05 Jul 2006 18:43:03 -0700</pubDate>
      <guid isPermaLink="false">urn:uuid:f9d7289d-7f9c-41dd-b513-c26004a82882</guid>
      <link>http://i.nfectio.us/articles/2006/02/05/rails-acts_as_threaded-plugin#comment-18</link>
    </item>
    <item>
      <title>"Rails acts_as_threaded Plugin" by steve mcghee</title>
      <description>be sure to check out bob's next post, taking this into the Model, as well as the comment regarding using to_i.  using that with this code, i also recommend another instance of to_i:

padding-left:#{thread.depth*20}")
=
padding-left:#{thread.depth.to_i*20}")


this way, you don't have to rely on mysql auto-inserting 0s for you.</description>
      <pubDate>Tue, 04 Jul 2006 20:36:12 -0700</pubDate>
      <guid isPermaLink="false">urn:uuid:c3e397b7-3ca0-4062-aaa6-e6a67bc69b69</guid>
      <link>http://i.nfectio.us/articles/2006/02/05/rails-acts_as_threaded-plugin#comment-17</link>
    </item>
    <item>
      <title>"Rails acts_as_threaded Plugin" by Leevi Graham</title>
      <description>Hi,

Im having some trouble installing this plugin. I have unzipped it to the plugins directory and followed the screen cast. However I recieve the following error:

undefinded local variable or method 'acts_as_threaded' for Category::Class

Any ideas?

Cheers Leevi</description>
      <pubDate>Sat, 24 Jun 2006 09:21:59 -0700</pubDate>
      <guid isPermaLink="false">urn:uuid:c6af64c3-32cf-49a7-9146-c81d9c3fea7d</guid>
      <link>http://i.nfectio.us/articles/2006/02/05/rails-acts_as_threaded-plugin#comment-6</link>
    </item>
  </channel>
</rss>
