<?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>Wyatt Baldwin &#187; acts_as_tree</title>
	<atom:link href="http://wyattbaldwin.com/tag/acts_as_tree/feed/" rel="self" type="application/rss+xml" />
	<link>http://wyattbaldwin.com</link>
	<description></description>
	<lastBuildDate>Tue, 20 Jul 2010 17:43:25 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>YUI TreeView with Ruby on Rails</title>
		<link>http://wyattbaldwin.com/2008/05/26/yui-treeview-with-ruby-on-rails/</link>
		<comments>http://wyattbaldwin.com/2008/05/26/yui-treeview-with-ruby-on-rails/#comments</comments>
		<pubDate>Tue, 27 May 2008 03:48:07 +0000</pubDate>
		<dc:creator>Wyatt</dc:creator>
				<category><![CDATA[dev]]></category>
		<category><![CDATA[acts_as_tree]]></category>
		<category><![CDATA[recursion]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[ruby on rails]]></category>
		<category><![CDATA[yui]]></category>

		<guid isPermaLink="false">http://wyattbaldwin.com/?p=184</guid>
		<description><![CDATA[Here&#8217;s some code I&#8217;m using to generate a dynamic tree view using an acts_as_tree model with slug and title fields, the TreeView widget from YUI, and a Rails helper. I chopped out some of the code for clarity, so all &#8230; <a href="http://wyattbaldwin.com/2008/05/26/yui-treeview-with-ruby-on-rails/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s some code I&#8217;m using to generate a dynamic tree view using an acts_as_tree model with slug and title fields, the TreeView widget from YUI, and a Rails helper. I chopped out some of the code for clarity, so all this does is create a menu with the titles from the model, but the basic idea is there to expand on.</p>
<p><strong>Rails view/JavaScript</strong></p>
<pre>&lt;script type="text/javascript"&gt;
  var page_tree;
  page_tree_init = function () {
    page_tree = new YAHOO.widget.TreeView('page_tree');
    var root = page_tree.getRoot();
    &lt;% generate_page_nodes(@root) {} %&gt;
    page_tree.draw();
  };
  page_tree_init();
&lt;/script&gt;
</pre>
<p><strong>Ruby</strong></p>
<pre>def generate_page_nodes(node, &amp;block)
  parent = node.parent
  node_name = node.slug.gsub('-', '_')
  parent_node_name = parent.nil? ? 'root' : parent.slug.gsub('-', '_')
  js = &lt;&lt;-JS
    var #{node_name} = new YAHOO.widget.MenuNode('&lt;span class="node_title"&gt;#{node.title}&lt;/span&gt;',
                                                 #{parent_node_name});
  JS
  concat(js, block.binding)
  children = node.children
  children.each { |c| generate_page_nodes(c, &amp;block) } unless children.empty?
end
</pre>
]]></content:encoded>
			<wfw:commentRss>http://wyattbaldwin.com/2008/05/26/yui-treeview-with-ruby-on-rails/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
