<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: named_scope with acts_as_tree</title>
	<atom:link href="http://www.railsgarden.com/2008/06/25/named_scope-with-acts_as_tree/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.railsgarden.com/2008/06/25/named_scope-with-acts_as_tree/</link>
	<description>A delicious blend of Ruby and Rails...</description>
	<lastBuildDate>Sun, 03 Jan 2010 16:28:10 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: benhughes</title>
		<link>http://www.railsgarden.com/2008/06/25/named_scope-with-acts_as_tree/comment-page-1/#comment-3427</link>
		<dc:creator>benhughes</dc:creator>
		<pubDate>Wed, 29 Jul 2009 11:11:48 +0000</pubDate>
		<guid isPermaLink="false">http://www.railsgarden.com/2008/06/25/named_scope-with-acts_as_tree/#comment-3427</guid>
		<description>Doing heirarchies more than one sub-level deep cannot be worked with easily since it requires recursive operations to do things like listing *all* children of a given top-level category. In your example above that&#039;s fine and in fact for what you&#039;re doing, since you have to iterate over everything anyways, I&#039;d simply calculate the counts of only the leaf nodes and then calculate in Ruby the counts of parent nodes up from there.

Anyways I can recommend a different approach to heirarchies called the nested set model (http://dev.mysql.com/tech-resources/articles/hierarchical-data.html).  With rails there are several plugins implementing this, just search on GitHub for &quot;nested_set&quot;.</description>
		<content:encoded><![CDATA[<p>Doing heirarchies more than one sub-level deep cannot be worked with easily since it requires recursive operations to do things like listing *all* children of a given top-level category. In your example above that&#8217;s fine and in fact for what you&#8217;re doing, since you have to iterate over everything anyways, I&#8217;d simply calculate the counts of only the leaf nodes and then calculate in Ruby the counts of parent nodes up from there.</p>
<p>Anyways I can recommend a different approach to heirarchies called the nested set model (<a href="http://dev.mysql.com/tech-resources/articles/hierarchical-data.html" rel="nofollow">http://dev.mysql.com/tech-resources/articles/hierarchical-data.html</a>).  With rails there are several plugins implementing this, just search on GitHub for &#8220;nested_set&#8221;.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Camilo Sáchez</title>
		<link>http://www.railsgarden.com/2008/06/25/named_scope-with-acts_as_tree/comment-page-1/#comment-3421</link>
		<dc:creator>Camilo Sáchez</dc:creator>
		<pubDate>Wed, 29 Jul 2009 03:27:50 +0000</pubDate>
		<guid isPermaLink="false">http://www.railsgarden.com/2008/06/25/named_scope-with-acts_as_tree/#comment-3421</guid>
		<description>Hi, in my las comment the categories tree are indented for subcategories...

Video Games (15)
------Nintendo DS (3)
-----------DS Games (1)
-----------DS Lite Consoles (2)
------Nintendo Wii (2)
-----------Wii Consoles (1)
----------Wii Games (1)
------PlayStation (10)
----------PS2 Consoles (6)
----------PS3 Accessories (4)</description>
		<content:encoded><![CDATA[<p>Hi, in my las comment the categories tree are indented for subcategories&#8230;</p>
<p>Video Games (15)<br />
&#8212;&#8212;Nintendo DS (3)<br />
&#8212;&#8212;&#8212;&#8211;DS Games (1)<br />
&#8212;&#8212;&#8212;&#8211;DS Lite Consoles (2)<br />
&#8212;&#8212;Nintendo Wii (2)<br />
&#8212;&#8212;&#8212;&#8211;Wii Consoles (1)<br />
&#8212;&#8212;&#8212;-Wii Games (1)<br />
&#8212;&#8212;PlayStation (10)<br />
&#8212;&#8212;&#8212;-PS2 Consoles (6)<br />
&#8212;&#8212;&#8212;-PS3 Accessories (4)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Camilo Sáchez</title>
		<link>http://www.railsgarden.com/2008/06/25/named_scope-with-acts_as_tree/comment-page-1/#comment-3420</link>
		<dc:creator>Camilo Sáchez</dc:creator>
		<pubDate>Wed, 29 Jul 2009 03:24:58 +0000</pubDate>
		<guid isPermaLink="false">http://www.railsgarden.com/2008/06/25/named_scope-with-acts_as_tree/#comment-3420</guid>
		<description>Hi Ben and thank you so much for this post!

But I have a questions.

How can this?

Video Games (15)
	Nintendo DS (3)
		DS Games (1)
		DS Lite Consoles (2)
	Nintendo Wii (2)
		Wii Consoles (1)
		Wii Games (1)
	PlayStation (10)
		PS2 Consoles (6)
		PS3 Accessories (4)

With you example i have two levels

I need four or five levels - recursive categories

(I need this bad sample)
:conditions =&gt; [&quot;categories.id = ? OR categories.parent_id OR categories.grandparent_id = ? OR .. (etc..)


How can count total Products in each parent level?
 
 CategoriesHelper code:

  def find_all_listsubcategories(category)
    if category.children.size &gt; 0
      ret = &#039;&#039;
      category.children.each { &#124;subcat&#124; 
          ret += &#039;&#039;
          ret += link_to h(subcat.name), :action =&gt; &#039;show&#039;, :id =&gt; subcat
          ret += &#039;&#039;
        }
      ret += &#039;&#039;
    end
  end


Can you help me please, I&#039;m not a developer. I&#039;m Web designer

Sorry, i don&#039;t speak english very well

thank you again!</description>
		<content:encoded><![CDATA[<p>Hi Ben and thank you so much for this post!</p>
<p>But I have a questions.</p>
<p>How can this?</p>
<p>Video Games (15)<br />
	Nintendo DS (3)<br />
		DS Games (1)<br />
		DS Lite Consoles (2)<br />
	Nintendo Wii (2)<br />
		Wii Consoles (1)<br />
		Wii Games (1)<br />
	PlayStation (10)<br />
		PS2 Consoles (6)<br />
		PS3 Accessories (4)</p>
<p>With you example i have two levels</p>
<p>I need four or five levels &#8211; recursive categories</p>
<p>(I need this bad sample)<br />
:conditions =&gt; [&#8220;categories.id = ? OR categories.parent_id OR categories.grandparent_id = ? OR .. (etc..)</p>
<p>How can count total Products in each parent level?</p>
<p> CategoriesHelper code:</p>
<p>  def find_all_listsubcategories(category)<br />
    if category.children.size &gt; 0<br />
      ret = &#8221;<br />
      category.children.each { |subcat|<br />
          ret += &#8221;<br />
          ret += link_to h(subcat.name), :action =&gt; &#8217;show&#8217;, :id =&gt; subcat<br />
          ret += &#8221;<br />
        }<br />
      ret += &#8221;<br />
    end<br />
  end</p>
<p>Can you help me please, I&#8217;m not a developer. I&#8217;m Web designer</p>
<p>Sorry, i don&#8217;t speak english very well</p>
<p>thank you again!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Javix</title>
		<link>http://www.railsgarden.com/2008/06/25/named_scope-with-acts_as_tree/comment-page-1/#comment-1868</link>
		<dc:creator>Javix</dc:creator>
		<pubDate>Tue, 10 Feb 2009 09:55:41 +0000</pubDate>
		<guid isPermaLink="false">http://www.railsgarden.com/2008/06/25/named_scope-with-acts_as_tree/#comment-1868</guid>
		<description>Hi, Ben! I&#039;d like to use acts_as_tree plusgin but I can&#039;t find any examples how to create a new sub-category inside of the given category(i.e. how to pass parent_id to &#039;enw-create-edit-update actions).Could you post a simple example, please.Thank you.</description>
		<content:encoded><![CDATA[<p>Hi, Ben! I&#8217;d like to use acts_as_tree plusgin but I can&#8217;t find any examples how to create a new sub-category inside of the given category(i.e. how to pass parent_id to &#8216;enw-create-edit-update actions).Could you post a simple example, please.Thank you.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: benhughes</title>
		<link>http://www.railsgarden.com/2008/06/25/named_scope-with-acts_as_tree/comment-page-1/#comment-1014</link>
		<dc:creator>benhughes</dc:creator>
		<pubDate>Fri, 29 Aug 2008 12:19:26 +0000</pubDate>
		<guid isPermaLink="false">http://www.railsgarden.com/2008/06/25/named_scope-with-acts_as_tree/#comment-1014</guid>
		<description>You could but that&#039;s an actual find method that returns results, not a scope.  My top scope above can be chained.  Also, Category.root just returns the *first* result with parent_id = nil (for the case where you have a category with a single root).  There is however a Category.roots that works the same way as my top, just not with a named_scope.</description>
		<content:encoded><![CDATA[<p>You could but that&#8217;s an actual find method that returns results, not a scope.  My top scope above can be chained.  Also, Category.root just returns the *first* result with parent_id = nil (for the case where you have a category with a single root).  There is however a Category.roots that works the same way as my top, just not with a named_scope.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Martin</title>
		<link>http://www.railsgarden.com/2008/06/25/named_scope-with-acts_as_tree/comment-page-1/#comment-1013</link>
		<dc:creator>Martin</dc:creator>
		<pubDate>Fri, 29 Aug 2008 10:15:30 +0000</pubDate>
		<guid isPermaLink="false">http://www.railsgarden.com/2008/06/25/named_scope-with-acts_as_tree/#comment-1013</guid>
		<description>For the first named_scope you could have also used the class method &quot;root&quot; baked into acts_as_tree:

Category.root</description>
		<content:encoded><![CDATA[<p>For the first named_scope you could have also used the class method &#8220;root&#8221; baked into acts_as_tree:</p>
<p>Category.root</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: essetLaf</title>
		<link>http://www.railsgarden.com/2008/06/25/named_scope-with-acts_as_tree/comment-page-1/#comment-886</link>
		<dc:creator>essetLaf</dc:creator>
		<pubDate>Sun, 03 Aug 2008 12:04:20 +0000</pubDate>
		<guid isPermaLink="false">http://www.railsgarden.com/2008/06/25/named_scope-with-acts_as_tree/#comment-886</guid>
		<description>Thank you</description>
		<content:encoded><![CDATA[<p>Thank you</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: mongo</title>
		<link>http://www.railsgarden.com/2008/06/25/named_scope-with-acts_as_tree/comment-page-1/#comment-802</link>
		<dc:creator>mongo</dc:creator>
		<pubDate>Wed, 16 Jul 2008 06:34:07 +0000</pubDate>
		<guid isPermaLink="false">http://www.railsgarden.com/2008/06/25/named_scope-with-acts_as_tree/#comment-802</guid>
		<description>thank you so much; i was looking for an example with the lambda *and* the association.</description>
		<content:encoded><![CDATA[<p>thank you so much; i was looking for an example with the lambda *and* the association.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
