From jonas at fkw.se Wed May 2 16:24:10 2007 From: jonas at fkw.se (jonas) Date: Wed, 2 May 2007 22:24:10 +0200 Subject: [Betternestedset-talk] Keep getting the MYSQL-error Message-ID: I?ve been working on a site tree with multiple roots for a while now. I just can?t figure out this error (that previously was mentioned here): Mysql::Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '? ? "site_id IS NULL" : "site_id = #{site_id}")' at line 1: SELECT max(rgt) AS max_rgt FROM nodes WHERE (site_id.nil? ? "site_id IS NULL" : "site_id = #{site_id}") My apps models: class Node < ActiveRecord::Base belongs_to :site acts_as_nested_set :scope => :site end class Site < ActiveRecord::Base has_many :nodes, :dependent => :delete_all end Columns in database: create_table "nodes", :force => true do |t| t.column "name", :string t.column "parent_id", :integer t.column "lft", :integer t.column "rgt", :integer t.column "site_id", :integer end What am I doing wrong? Best regards Jonas -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/betternestedset-talk/attachments/20070502/08d1d76b/attachment.html From dontfall at gmail.com Thu May 3 10:12:48 2007 From: dontfall at gmail.com (Krishna Dole) Date: Thu, 3 May 2007 10:12:48 -0400 Subject: [Betternestedset-talk] Keep getting the MYSQL-error In-Reply-To: References: Message-ID: <8d64b97d0705030712v7b1fb889wd5ecd0cf235af22@mail.gmail.com> Hi Jonas, Do all the tests run successfully for you? Krishna On 5/2/07, jonas wrote: > I?ve been working on a site tree with multiple roots for a while now. I just > can?t figure out this error (that previously was mentioned here): > > Mysql::Error: You have an error in your SQL syntax; check the manual that > corresponds to your MySQL server version for the right syntax to use near '? > ? "site_id IS NULL" : "site_id = #{site_id}")' at line 1: SELECT max(rgt) AS > max_rgt FROM nodes WHERE (site_id.nil? ? "site_id IS NULL" : "site_id = > #{site_id}") > > My apps models: > > class Node < ActiveRecord::Base > belongs_to :site > acts_as_nested_set :scope => :site > end > > class Site < ActiveRecord::Base > has_many :nodes, :dependent => :delete_all > end > > Columns in database: > create_table "nodes", :force => true do |t| > t.column "name", :string > t.column "parent_id", :integer > t.column "lft", :integer > t.column "rgt", :integer > t.column "site_id", :integer > end > > What am I doing wrong? > > > Best regards > Jonas > > _______________________________________________ > Betternestedset-talk mailing list > Betternestedset-talk at rubyforge.org > http://rubyforge.org/mailman/listinfo/betternestedset-talk > > From jonas at fkw.se Thu May 3 17:25:22 2007 From: jonas at fkw.se (jonas) Date: Thu, 3 May 2007 23:25:22 +0200 Subject: [Betternestedset-talk] =?iso-8859-1?q?Don=B4t_bother=2E=2E=2E?= Message-ID: Don?t bother. I had just forgotten to update my source. I?ve solved it and thank you for taking time. This plugin rocks! Kind Regards Jonas ---------------------------------------- Fr?n: "Mark.noten" Skickat: den 3 maj 2007 11:22 Till: jonas at fkw.se ?mne: SPAM-LOW: Re: [Betternestedset-talk] Keep getting the MYSQL-error Hi Jonas, I'm not an expert in this but it looks like a part of your query building method is badly escaped. ? ? "site_id IS NULL" : "site_id = #{site_id}") Looks like you're trying to do something like below. It's a shorted version of the "if" syntax. site_id.nil? "site_id IS NULL" : "site_id = #{site_id}" Kind regards, Mark Noten Zaakvoerder ITFC gcv E-mail: mark.noten at itfc.be GSM: 0484/698333 --------- Original Message -------- From: jonas at fkw.se To: betternestedset-talk at rubyforge.org Subject: [Betternestedset-talk] Keep getting the MYSQL-error Date: 02/05/07 23:40 > I?ve been working on a site tree with multiple roots for a while now. I just can?t figure out this error (that previously was mentioned here):Mysql::Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '? ? "site_id IS NULL" : "site_id = #{site_id}")' at line 1: SELECT max(rgt) AS max_rgt FROM nodes WHERE (site_id.nil? ? "site_id IS NULL" : "site_id = #{site_id}")My apps models:class Node < ActiveRecord::Base belongs_to :site acts_as_nested_set :scope => :siteendclass Site < ActiveRecord::Base has_many :nodes, :dependent => :delete_allendColumns in database: create_table "nodes", :force => true do |t| t.column "name", :string t.column "parent_id", :integer t.column "lft", :integer t.column "rgt", :integer t.column "site_id", :integer endWhat am I doing wrong?Best regardsJonas > > > > > > _______________________________________________ > Betternestedset-talk mailing list > Betternestedset-talk at rubyforge.org > http://rubyforge.org/mailman/listinfo/betternestedset-talk > ________________________________________________ Message sent using UebiMiau 2.7.10 -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/betternestedset-talk/attachments/20070503/f2fd5992/attachment.html From masterkain at gmail.com Mon May 7 09:44:13 2007 From: masterkain at gmail.com (Claudio Poli) Date: Mon, 7 May 2007 15:44:13 +0200 Subject: [Betternestedset-talk] example controller and one question Message-ID: <51263840-13D4-4D50-AC8E-4246D7188D1D@gmail.com> hi there, I started using better nested set, however there are things that aren't too clear for me. I'm in the process of building a small interface to manage a simple Category model that can have multiple roots. I've tried to scope them but I got strange errors, is there anybody that can provide a sample controller to manage categories? Also, I need to display the whole Category tree, I've tried to look at full_set and helper, but I really can't find an answer. Thanks in advance for any hints. From mark.noten at itfc.be Thu May 24 17:12:29 2007 From: mark.noten at itfc.be (Noten Mark) Date: Thu, 24 May 2007 23:12:29 +0200 Subject: [Betternestedset-talk] Trouble with tree view Message-ID: <200705242312.29611.mark.noten@itfc.be> Hi all, I'm struggling a bit with displaying a subtree with all the child nodes of a node. A node in this case is an Agent model extending ActiveRecord::Base and using acts_as_nested_set :scope => :product_id. I would like to generate the below HTML code that displays a tree. The ASCII connectors can easily be replaced by icons.
node 1
|-node 1.1
|-node 1.2
|  |-node 1.2.1
|  \-node 1.2.2
\-node 1.3
node 2 I have this method defined in the AgentsHelper module: def show_agents_tree(current_agent, child_agents) html = "\n" html += "\n" if !agents.empty? html += "\n" end html += "
#{agent_link(current_agent)}
\n" html += show_agents_tree(agents.shift, child_agents) html += "
\n" end It generates HTML code that just displays each agent as a child of the previous agent. Can anyone help me to get the right level (O, 1, 2, ...) dependent indentation working? Any help is appreciated. Thanks, Mark From mark.noten at itfc.be Fri May 25 04:12:31 2007 From: mark.noten at itfc.be (Mark.noten) Date: Fri, 25 May 2007 10:12:31 +0200 Subject: [Betternestedset-talk] Trouble with tree view Message-ID: Some extra information: manager.all_children = child_agents And agents.shift should be child_agents.shift Kind regards, Mark --------- Original Message -------- From: betternestedset-talk at rubyforge.org To: betternestedset-talk at rubyforge.org Subject: [Betternestedset-talk] Trouble with tree view Date: 25/05/07 00:23 > Hi all, > > I'm struggling a bit with displaying a subtree with all the child nodes of a > node. A node in this case is an Agent model extending ActiveRecord::Base and > using acts_as_nested_set :scope => :product_id. > > I would like to generate the below HTML code that displays a tree. The ASCII > connectors can easily be replaced by icons. > > <table border=0 cellspacing=0 cellpadding=0> > <tr><td nowrap><b>node 1</b></td></tr> > <tr><td> > <table border=0 cellspacing=0 cellpadding=0> > <tr> > <table border=0 cellspacing=0 cellpadding=0> > <tr><td nowrap>|-</td><td nowrap>node 1.1</td></tr></table> > </tr> > <tr> > <table border=0 cellspacing=0 cellpadding=0> > <tr><td nowrap>|-</td><td nowrap>node 1.2</td></tr></table> > </tr> > <tr><td> > <table border=0 cellspacing=0 cellpadding=0> > <tr> > <table border=0 cellspacing=0 cellpadding=0> > <tr><td nowrap>|&nbsp;&nbsp;</td><td nowrap>|-</td><td nowrap>node > 1.2.1</td></tr></table> > </tr> > <tr> > <table border=0 cellspacing=0 cellpadding=0> > <tr><td nowrap>|&nbsp;&nbsp;</td><td nowrap>-</td><td nowrap>node > 1.2.2</td></tr></table> > </tr> > </table> > </td></tr> > <tr> > <table border=0 cellspacing=0 cellpadding=0> > <tr><td nowrap>-</td><td nowrap>node 1.3</td></tr></table> > </tr> > </table> > </td></tr> > <tr><td nowrap>node 2</td></tr> > </table> > > I have this method defined in the AgentsHelper module: > > def show_agents_tree(current_agent, child_agents) > html = "<table class="agent-tree">n" > html += "<tr><td nowrap>#{agent_link(current_agent)}</td></tr>n" > if !agents.empty? > html += "<tr><td>n" > html += show_agents_tree(agents.shift, child_agents) > html += "</td></tr>n" > end > html += "</table>n" > end > > It generates HTML code that just displays each agent as a child of the > previous agent. Can anyone help me to get the right level (O, 1, 2, ...) > dependent indentation working? Any help is appreciated. > > Thanks, > > Mark > _______________________________________________ > Betternestedset-talk mailing list > Betternestedset-talk at rubyforge.org > http://rubyforge.org/mailman/listinfo/betternestedset-talk > > ________________________________________________ Message sent using UebiMiau 2.7.10 From mark.noten at itfc.be Sun May 27 14:05:11 2007 From: mark.noten at itfc.be (Noten Mark) Date: Sun, 27 May 2007 20:05:11 +0200 Subject: [Betternestedset-talk] Trouble with tree view In-Reply-To: References: Message-ID: <200705272005.11950.mark.noten@itfc.be> Hi all, after some extensive searching I found an recursive algorithm to dislay a tree structure on http://snippets.dzone.com/posts/show/1919. I modified it only slightly and I thought I would share the code with you. In application_helper.rb: def display_tree_recursive(tree, parent_id) ret = "
    \n" tree.each do |node| if node.parent_id == parent_id ret += "\t
  • " ret += yield node ret += display_tree_recursive(tree, node.id) { |n| yield n } if node.all_children_count > 0 ret += "
  • \n" end end ret += "
\n" end You can call it in the view show.rhtml with @tree = node.full_set and @parent_id = node.parent_id where node = BNSModel.find(params[:id]) set in the show action: <%= display_tree_recursive(@tree, @parent_id) {|node| node.name} %> (Actually I use another helper method to avoid the code block in the view). With the "if node.all_children_count > 0" statement, no extra query is needed to determine if the node has any children. ;-) With some CSS magic (wrap it with
and defining layouts for
    and
  • ) you can get a really nice looking tree. Maybe someone has an example. Kind regards, Mark On Friday 25 May 2007 10:12, Mark.noten wrote: > Some extra information: > > manager.all_children = child_agents > > And agents.shift should be child_agents.shift > > Kind regards, > > Mark > --------- Original Message -------- > From: betternestedset-talk at rubyforge.org > To: betternestedset-talk at rubyforge.org > Subject: [Betternestedset-talk] Trouble with tree view > Date: 25/05/07 00:23 > > > Hi all, > > > > I'm struggling a bit with displaying a subtree with all the child nodes > > of > > a > > > node. A node in this case is an Agent model extending ActiveRecord::Base > > and > > > using acts_as_nested_set :scope => :product_id. > > > > I would like to generate the below HTML code that displays a tree. The > > ASCII > > > connectors can easily be replaced by icons. > > > > <table border=0 cellspacing=0 cellpadding=0> > > <tr><td nowrap><b>node > > 1</b></td></tr> <tr><td> > > <table border=0 cellspacing=0 cellpadding=0> > > <tr> > > <table border=0 cellspacing=0 cellpadding=0> > > <tr><td nowrap>|-</td><td nowrap>node > > 1.1</td></tr></table> > > > </tr> > > <tr> > > <table border=0 cellspacing=0 cellpadding=0> > > <tr><td nowrap>|-</td><td nowrap>node > > 1.2</td></tr></table> > > > </tr> > > <tr><td> > > <table border=0 cellspacing=0 cellpadding=0> > > <tr> > > <table border=0 cellspacing=0 cellpadding=0> > > <tr><td nowrap>|&nbsp;&nbsp;</td><td > > nowrap>|-</td><td nowrap>node > > > 1.2.1</td></tr></table> > > </tr> > > <tr> > > <table border=0 cellspacing=0 cellpadding=0> > > <tr><td nowrap>|&nbsp;&nbsp;</td><td > > nowrap>-</td><td nowrap>node > > > 1.2.2</td></tr></table> > > </tr> > > </table> > > </td></tr> > > <tr> > > <table border=0 cellspacing=0 cellpadding=0> > > <tr><td nowrap>-</td><td nowrap>node > > 1.3</td></tr></table> > > > </tr> > > </table> > > </td></tr> > > <tr><td nowrap>node 2</td></tr> > > </table> > > > > I have this method defined in the AgentsHelper module: > > > > def show_agents_tree(current_agent, child_agents) > > html = "<table class="agent-tree">n" > > html += "<tr><td > > nowrap>#{agent_link(current_agent)}</td></tr>n" > > > if !agents.empty? > > html += "<tr><td>n" > > html += show_agents_tree(agents.shift, child_agents) > > html += "</td></tr>n" > > end > > html += "</table>n" > > end > > > > It generates HTML code that just displays each agent as a child of the > > previous agent. Can anyone help me to get the right level (O, 1, 2, ...) > > dependent indentation working? Any help is appreciated. > > > > Thanks, > > > > Mark > > _______________________________________________ > > Betternestedset-talk mailing list > > Betternestedset-talk at rubyforge.org > > http://rubyforge.org/mailman/listinfo/betternestedset-talk > > ________________________________________________ > Message sent using UebiMiau 2.7.10 > > > _______________________________________________ > Betternestedset-talk mailing list > Betternestedset-talk at rubyforge.org > http://rubyforge.org/mailman/listinfo/betternestedset-talk -- Met vriendelijke groet, Mark Noten Software engineer ITFC gcv Email: mark.noten at itfc.be GSM: +32 (484) 698 333 From masterkain at gmail.com Mon May 28 08:54:59 2007 From: masterkain at gmail.com (Claudio Poli) Date: Mon, 28 May 2007 14:54:59 +0200 Subject: [Betternestedset-talk] Trouble with tree view In-Reply-To: <200705272005.11950.mark.noten@itfc.be> References: <200705272005.11950.mark.noten@itfc.be> Message-ID: <47E4309B-D326-4C20-937E-E44131C65179@gmail.com> hi Mark, thanks for sharing this useful piece of code. does you or somebody have a hint for this problem? - root1 -- subcategory -- subcategory - root2 -- subcategory -- subcategory --- subcategory ie. what's the usual setup to have multiple roots and to display them in a view, maybe ordered in some ways? currently I'm using <% for root in @categories %>
      <% for node in root.full_set %>
    • <%= '-' * node.level %> <%= link_to node.name, category_path (node) %>
    • <% end %>
    <% end %> with @categories = Category.roots thanks. Il giorno 27/mag/07, alle ore 20:05, Noten Mark ha scritto: > Hi all, > > after some extensive searching I found an recursive algorithm to > dislay a tree > structure on http://snippets.dzone.com/posts/show/1919. I modified > it only > slightly and I thought I would share the code with you. > > In application_helper.rb: > > def display_tree_recursive(tree, parent_id) > ret = "
      \n" > tree.each do |node| > if node.parent_id == parent_id > ret += "\t
    • " > ret += yield node > ret += display_tree_recursive(tree, node.id) { |n| yield > n } if > node.all_children_count > 0 > ret += "
    • \n" > end > end > ret += "
    \n" > end > > You can call it in the view show.rhtml with @tree = node.full_set and > @parent_id = node.parent_id where node = BNSModel.find(params[:id]) > set in > the show action: > > <%= display_tree_recursive(@tree, @parent_id) {|node| node.name} %> > (Actually I use another helper method to avoid the code block in > the view). > > With the "if node.all_children_count > 0" statement, no extra query > is needed > to determine if the node has any children. ;-) > > With some CSS magic (wrap it with
    and defining > layouts for >
      and
    • ) you can get a really nice looking tree. Maybe > someone has an > example. > > Kind regards, > > Mark > > On Friday 25 May 2007 10:12, Mark.noten wrote: >> Some extra information: >> >> manager.all_children = child_agents >> >> And agents.shift should be child_agents.shift >> >> Kind regards, >> >> Mark >> --------- Original Message -------- >> From: betternestedset-talk at rubyforge.org >> To: betternestedset-talk at rubyforge.org > talk at rubyforge.org> >> Subject: [Betternestedset-talk] Trouble with tree view >> Date: 25/05/07 00:23 >> >>> Hi all, >>> >>> I'm struggling a bit with displaying a subtree with all the child >>> nodes >>> of >> >> a >> >>> node. A node in this case is an Agent model extending >>> ActiveRecord::Base >> >> and >> >>> using acts_as_nested_set :scope => :product_id. >>> >>> I would like to generate the below HTML code that displays a >>> tree. The >> >> ASCII >> >>> connectors can easily be replaced by icons. >>> >>> <table border=0 cellspacing=0 cellpadding=0> >>> <tr><td nowrap><b>node >>> 1</b></td></tr> <tr><td> >>> <table border=0 cellspacing=0 cellpadding=0> >>> <tr> >>> <table border=0 cellspacing=0 cellpadding=0> >>> <tr><td nowrap>|-</td><td nowrap>node >> >> 1.1</td></tr></table> >> >>> </tr> >>> <tr> >>> <table border=0 cellspacing=0 cellpadding=0> >>> <tr><td nowrap>|-</td><td nowrap>node >> >> 1.2</td></tr></table> >> >>> </tr> >>> <tr><td> >>> <table border=0 cellspacing=0 cellpadding=0> >>> <tr> >>> <table border=0 cellspacing=0 cellpadding=0> >>> <tr><td nowrap>|&nbsp;&nbsp;</td><td >> >> nowrap>|-</td><td nowrap>node >> >>> 1.2.1</td></tr></table> >>> </tr> >>> <tr> >>> <table border=0 cellspacing=0 cellpadding=0> >>> <tr><td nowrap>|&nbsp;&nbsp;</td><td >> >> nowrap>-</td><td nowrap>node >> >>> 1.2.2</td></tr></table> >>> </tr> >>> </table> >>> </td></tr> >>> <tr> >>> <table border=0 cellspacing=0 cellpadding=0> >>> <tr><td nowrap>-</td><td nowrap>node >> >> 1.3</td></tr></table> >> >>> </tr> >>> </table> >>> </td></tr> >>> <tr><td nowrap>node 2</td></tr> >>> </table> >>> >>> I have this method defined in the AgentsHelper module: >>> >>> def show_agents_tree(current_agent, child_agents) >>> html = "<table class="agent-tree">n" >>> html += "<tr><td >> >> nowrap>#{agent_link(current_agent)}</td></tr>n" >> >>> if !agents.empty? >>> html += "<tr><td>n" >>> html += show_agents_tree(agents.shift, child_agents) >>> html += "</td></tr>n" >>> end >>> html += "</table>n" >>> end >>> >>> It generates HTML code that just displays each agent as a child >>> of the >>> previous agent. Can anyone help me to get the right level (O, 1, >>> 2, ...) >>> dependent indentation working? Any help is appreciated. >>> >>> Thanks, >>> >>> Mark >>> _______________________________________________ >>> Betternestedset-talk mailing list >>> Betternestedset-talk at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/betternestedset-talk >> >> ________________________________________________ >> Message sent using UebiMiau 2.7.10 >> >> >> _______________________________________________ >> Betternestedset-talk mailing list >> Betternestedset-talk at rubyforge.org >> http://rubyforge.org/mailman/listinfo/betternestedset-talk > > -- > Met vriendelijke groet, > > Mark Noten > Software engineer > ITFC gcv > Email: mark.noten at itfc.be > GSM: +32 (484) 698 333 > _______________________________________________ > Betternestedset-talk mailing list > Betternestedset-talk at rubyforge.org > http://rubyforge.org/mailman/listinfo/betternestedset-talk From mark.noten at itfc.be Mon May 28 13:24:38 2007 From: mark.noten at itfc.be (Noten Mark) Date: Mon, 28 May 2007 19:24:38 +0200 Subject: [Betternestedset-talk] Trouble with tree view In-Reply-To: <47E4309B-D326-4C20-937E-E44131C65179@gmail.com> References: <200705272005.11950.mark.noten@itfc.be> <47E4309B-D326-4C20-937E-E44131C65179@gmail.com> Message-ID: <200705281924.38713.mark.noten@itfc.be> Hi Claudio, if you look at the bottom of this link http://snippets.dzone.com/posts/show/1919 then you'll find what you need. You can use the display_tree_recursive function that I posted in your view like this: <%= display_tree_recursive(@tree, nil) %> In the action of your controller just put something like: @tree = Category.find(:all, :order => 'product_id, lft') If have multiple roots with :scope => :product_id so the above statement sorts each tree by product_id (1, 2, ...) and then each tree is sorted with the root first, then it's children from left to right, ... (like normally when working with better nested set). I'm sure other people have a better solution because this one generaties quite some calls to the display_tree_recursive function. Claudio, you also better but your code in an helper method to keep a clean view. Kind regards, Mark On Monday 28 May 2007 14:54, Claudio Poli wrote: > hi Mark, > thanks for sharing this useful piece of code. > does you or somebody have a hint for this problem? > > - root1 > -- subcategory > -- subcategory > - root2 > -- subcategory > -- subcategory > --- subcategory > > ie. what's the usual setup to have multiple roots and to display them > in a view, maybe ordered in some ways? > > currently I'm using > <% for root in @categories %> >
        > <% for node in root.full_set %> >
      • <%= '-' * node.level %> <%= link_to node.name, category_path > (node) %>
      • > <% end %> >
      > <% end %> > > with > > @categories = Category.roots > > thanks. > > Il giorno 27/mag/07, alle ore 20:05, Noten Mark ha scritto: > > Hi all, > > > > after some extensive searching I found an recursive algorithm to > > dislay a tree > > structure on http://snippets.dzone.com/posts/show/1919. I modified > > it only > > slightly and I thought I would share the code with you. > > > > In application_helper.rb: > > > > def display_tree_recursive(tree, parent_id) > > ret = "
        \n" > > tree.each do |node| > > if node.parent_id == parent_id > > ret += "\t
      • " > > ret += yield node > > ret += display_tree_recursive(tree, node.id) { |n| yield > > n } if > > node.all_children_count > 0 > > ret += "
      • \n" > > end > > end > > ret += "
      \n" > > end > > > > You can call it in the view show.rhtml with @tree = node.full_set and > > @parent_id = node.parent_id where node = BNSModel.find(params[:id]) > > set in > > the show action: > > > > <%= display_tree_recursive(@tree, @parent_id) {|node| node.name} %> > > (Actually I use another helper method to avoid the code block in > > the view). > > > > With the "if node.all_children_count > 0" statement, no extra query > > is needed > > to determine if the node has any children. ;-) > > > > With some CSS magic (wrap it with
      and defining > > layouts for > >
        and
      • ) you can get a really nice looking tree. Maybe > > someone has an > > example. > > > > Kind regards, > > > > Mark > > > > On Friday 25 May 2007 10:12, Mark.noten wrote: > >> Some extra information: > >> > >> manager.all_children = child_agents > >> > >> And agents.shift should be child_agents.shift > >> > >> Kind regards, > >> > >> Mark > >> --------- Original Message -------- > >> From: betternestedset-talk at rubyforge.org > >> To: betternestedset-talk at rubyforge.org >> talk at rubyforge.org> > >> Subject: [Betternestedset-talk] Trouble with tree view > >> Date: 25/05/07 00:23 > >> > >>> Hi all, > >>> > >>> I'm struggling a bit with displaying a subtree with all the child > >>> nodes > >>> of > >> > >> a > >> > >>> node. A node in this case is an Agent model extending > >>> ActiveRecord::Base > >> > >> and > >> > >>> using acts_as_nested_set :scope => :product_id. > >>> > >>> I would like to generate the below HTML code that displays a > >>> tree. The > >> > >> ASCII > >> > >>> connectors can easily be replaced by icons. > >>> > >>> <table border=0 cellspacing=0 cellpadding=0> > >>> <tr><td nowrap><b>node > >>> 1</b></td></tr> <tr><td> > >>> <table border=0 cellspacing=0 cellpadding=0> > >>> <tr> > >>> <table border=0 cellspacing=0 cellpadding=0> > >>> <tr><td nowrap>|-</td><td nowrap>node > >> > >> 1.1</td></tr></table> > >> > >>> </tr> > >>> <tr> > >>> <table border=0 cellspacing=0 cellpadding=0> > >>> <tr><td nowrap>|-</td><td nowrap>node > >> > >> 1.2</td></tr></table> > >> > >>> </tr> > >>> <tr><td> > >>> <table border=0 cellspacing=0 cellpadding=0> > >>> <tr> > >>> <table border=0 cellspacing=0 cellpadding=0> > >>> <tr><td nowrap>|&nbsp;&nbsp;</td><td > >> > >> nowrap>|-</td><td nowrap>node > >> > >>> 1.2.1</td></tr></table> > >>> </tr> > >>> <tr> > >>> <table border=0 cellspacing=0 cellpadding=0> > >>> <tr><td nowrap>|&nbsp;&nbsp;</td><td > >> > >> nowrap>-</td><td nowrap>node > >> > >>> 1.2.2</td></tr></table> > >>> </tr> > >>> </table> > >>> </td></tr> > >>> <tr> > >>> <table border=0 cellspacing=0 cellpadding=0> > >>> <tr><td nowrap>-</td><td nowrap>node > >> > >> 1.3</td></tr></table> > >> > >>> </tr> > >>> </table> > >>> </td></tr> > >>> <tr><td nowrap>node 2</td></tr> > >>> </table> > >>> > >>> I have this method defined in the AgentsHelper module: > >>> > >>> def show_agents_tree(current_agent, child_agents) > >>> html = "<table class="agent-tree">n" > >>> html += "<tr><td > >> > >> nowrap>#{agent_link(current_agent)}</td></tr>n" > >> > >>> if !agents.empty? > >>> html += "<tr><td>n" > >>> html += show_agents_tree(agents.shift, child_agents) > >>> html += "</td></tr>n" > >>> end > >>> html += "</table>n" > >>> end > >>> > >>> It generates HTML code that just displays each agent as a child > >>> of the > >>> previous agent. Can anyone help me to get the right level (O, 1, > >>> 2, ...) > >>> dependent indentation working? Any help is appreciated. > >>> > >>> Thanks, > >>> > >>> Mark > >>> _______________________________________________ > >>> Betternestedset-talk mailing list > >>> Betternestedset-talk at rubyforge.org > >>> http://rubyforge.org/mailman/listinfo/betternestedset-talk > >> > >> ________________________________________________ > >> Message sent using UebiMiau 2.7.10 > >> > >> > >> _______________________________________________ > >> Betternestedset-talk mailing list > >> Betternestedset-talk at rubyforge.org > >> http://rubyforge.org/mailman/listinfo/betternestedset-talk > > > > -- > > Met vriendelijke groet, > > > > Mark Noten > > Software engineer > > ITFC gcv > > Email: mark.noten at itfc.be > > GSM: +32 (484) 698 333 > > _______________________________________________ > > Betternestedset-talk mailing list > > Betternestedset-talk at rubyforge.org > > http://rubyforge.org/mailman/listinfo/betternestedset-talk > > _______________________________________________ > Betternestedset-talk mailing list > Betternestedset-talk at rubyforge.org > http://rubyforge.org/mailman/listinfo/betternestedset-talk -- Met vriendelijke groet, Mark Noten Software engineer ITFC gcv Email: mark.noten at itfc.be GSM: +32 (484) 698 333 From jc.michel at symetrie.com Mon May 28 17:50:20 2007 From: jc.michel at symetrie.com (Jean-Christophe Michel) Date: Mon, 28 May 2007 23:50:20 +0200 Subject: [Betternestedset-talk] Trouble with tree view In-Reply-To: <200705242312.29611.mark.noten@itfc.be> References: <200705242312.29611.mark.noten@itfc.be> Message-ID: Hi, Le 24 mai 07 ? 23:12, Noten Mark a ?crit : > I'm struggling a bit with displaying a subtree with all the child > nodes of a > node. A node in this case is an Agent model extending > ActiveRecord::Base and > using acts_as_nested_set :scope => :product_id. I just posted on http://opensource.symetrie.com/trac/better_nested_set/wiki/RecursiveMenu an example of a helper I use to display a dynamic menu with selected path developped (only the hierarchies in the selected path are open). Hope it will help with your question. Jean-Christophe Michel -- symetrie.com Better Nested Set for rails: http://opensource.symetrie.com/trac/better_nested_set