Chris O''Connor
2007-Jan-14 19:56 UTC
[Betternestedset-talk] Noob with trouble getting started with BetterNestedSet
Hello all, Would love to use this plugin--looks exactly like what is needed to model a given site''s hierarchy. And yet, as a noob (on many levels), I''m having a particularly hard time getting started with it. A tutorial that walked through scaffolding and basic presentation (start to finish) would be SO helpful. For example, my migration throws an error when I try to apply the :scope => :root_id in the model, as shown in the example given at http://wiki.rubyonrails.org/rails/pages/BetterNestedSet. If I remove that scope qualification, I can play with it in the console window, and I BELIEVE I understand the creation sequence and methods, but when it comes to putting together solid scaffolding for this model and actually SHOWING the FULL tree (or even partial trees from a particular node), I get lost quickly. And how does one remove a node cleanly? Any help would be appreciated. And thanks for your patience. -- Chris O''Connor http://www.choipaint.com/ -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/betternestedset-talk/attachments/20070114/0570d31b/attachment.html
Krishna Dole
2007-Jan-14 22:09 UTC
[Betternestedset-talk] Noob with trouble getting started with BetterNestedSet
Hey Chris, Welcome to the list. I agree we need a nice walk-through tutorial. Our code may undergo some changes soon though, so I''m sort of waiting until thing settle out before putting it together.> For example, my migration throws an error when I try to apply the :scope => > :root_id in the model, as shown in the example given at > http://wiki.rubyonrails.org/rails/pages/BetterNestedSet.What error are you seeing? Remember that you only need a scope if you are working with multiple trees.> > If I remove that scope qualification, I can play with it in the console > window, and I BELIEVE I understand the creation sequence and methods, but > when it comes to putting together solid scaffolding for this model and > actually SHOWING the FULL tree (or even partial trees from a particular > node), I get lost quickly. And how does one remove a node cleanly?It is up to you how you want to display the tree, but as a basic example for showing the whole tree: @items = SetModel.root.full_set then in the view you would loop through @items, and, quoting JCM: "You can use style="margin-left:<%= item.level %>em;" in your view to have items indented according to their level." (There are performance problems with calling #level so many times, but it should get you started). If you want an AJAX tree viewer, LiveTree is a Rails plugin that works nicely with nested sets: http://www.epiphyte.ca/code/live_tree.html The plugin handles cleanly deleting nodes for you (there is a callback that destroys all descendants), so just call node.destroy. k
Jean-Christophe Michel
2007-Jan-14 22:22 UTC
[Betternestedset-talk] Noob with trouble getting started with BetterNestedSet
Hi, Le 14 janv. 07, ? 20:56, Chris O''Connor a ?crit :> For example, my migration throws an error when I try to apply the > :scope => :root_id in the model, as shown in the example given at > http://wiki.rubyonrails.org/rails/pages/BetterNestedSet.WHat error ? are you sure your table has a root_id entry ?> If I remove that scope qualification, I can play with it in the > console window, and I BELIEVE I understand the creation sequence and > methods, but when it comes to putting together solid scaffolding for > this model and actually SHOWING the FULL tree (or even partial trees > from a particular node), I get lost quickly.See the helper to do such thing. We will post additional examples on how to display and edit a whole tree soon.> And how does one remove a node cleanly?my_node.destroy Jean-Christophe Michel -- symetrie.com Better Nested Set for rails: http://opensource.symetrie.com/trac/better_nested_set
Chris O''Connor
2007-Jan-31 03:54 UTC
[Betternestedset-talk] Noob with trouble getting started with BetterNestedSet
Thanks to all for the replies, I''ve been on another project and haven''t had time to come back to this, but now here I am again. With a class called ''TreeItem'', (table: ''tree_items''), and simple input from the console I get this error: # from ruby console window>> child = TreeItem.new(:name => "my_computer")SyntaxError: ./script/../config/../config/../app/models/tree_item.rb:2: parse er ror, unexpected tASSOC, expecting tCOLON2 or ''['' or ''.'' acts_as_nested_set, :scope => :root_id ^ from C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport- 1.3.1.584 8/lib/active_support/dependencies.rb:204:in `load_without_new_constant_marking'' from C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport- 1.3.1.584 8/lib/active_support/dependencies.rb:204:in `load_file'' from C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport- 1.3.1.584 8/lib/active_support/dependencies.rb:343:in `new_constants_in'' from C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport- 1.3.1.584 8/lib/active_support/dependencies.rb:203:in `load_file'' from C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport- 1.3.1.584 8/lib/active_support/dependencies.rb:95:in `require_or_load'' from C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport- 1.3.1.584 8/lib/active_support/dependencies.rb:249:in `load_missing_constant'' from C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport- 1.3.1.584 8/lib/active_support/dependencies.rb:453:in `const_missing'' from C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport- 1.3.1.584 8/lib/active_support/dependencies.rb:465:in `const_missing'' from (irb):3>>My model file: #tree_item.rb class TreeItem < ActiveRecord::Base acts_as_nested_set, :scope => :root_id end my data in mysql from monitor: mysql> select * from tree_items; +----+---------+-----------+------+------+------------------------+ | id | root_id | parent_id | lft | rgt | name | +----+---------+-----------+------+------+------------------------+ | 1 | 1 | NULL | 1 | 2 | ruby | | 2 | 2 | NULL | 1 | 2 | rails | | 3 | 3 | NULL | 1 | 6 | computers | | 4 | 3 | 3 | 2 | 3 | apple | | 5 | 3 | 3 | 4 | 5 | dell | | 6 | 6 | NULL | 1 | 8 | rails plug-ins | | 7 | 6 | 6 | 2 | 3 | better_nested_set | | 8 | 8 | NULL | 1 | 2 | frameworks | | 9 | 6 | 6 | 4 | 5 | restful_authentication | | 10 | 6 | 6 | 6 | 7 | authorization | | 11 | 11 | NULL | 1 | 2 | databases | +----+---------+-----------+------+------+------------------------+ 11 rows in set (0.13 sec) (you''ll have to trust me I guess)... What''s more curious is if I remove the :scope => :root_id I can work with the console all i like--making new children, saving them and moving them to others. I can even list the items in a view; however, they are not in the order I would hope for (due to no scope, yes?). Is there something obvious I''m missing? Thanks, Chris On 1/14/07, Krishna Dole <dontfall at gmail.com> wrote:> > Hey Chris, > > Welcome to the list. I agree we need a nice walk-through tutorial. Our > code may undergo some changes soon though, so I''m sort of waiting > until thing settle out before putting it together. > > > For example, my migration throws an error when I try to apply the :scope > => > > :root_id in the model, as shown in the example given at > > http://wiki.rubyonrails.org/rails/pages/BetterNestedSet. > > What error are you seeing? Remember that you only need a scope if you > are working with multiple trees. > > > > > If I remove that scope qualification, I can play with it in the console > > window, and I BELIEVE I understand the creation sequence and methods, > but > > when it comes to putting together solid scaffolding for this model and > > actually SHOWING the FULL tree (or even partial trees from a particular > > node), I get lost quickly. And how does one remove a node cleanly? > > It is up to you how you want to display the tree, but as a basic > example for showing the whole tree: > @items = SetModel.root.full_set > then in the view you would loop through @items, and, quoting JCM: "You > can use style="margin-left:<%= item.level %>em;" in your view to have > items indented according to their level." (There are performance > problems with calling #level so many times, but it should get you > started). > > If you want an AJAX tree viewer, LiveTree is a Rails plugin that works > nicely with nested sets: > http://www.epiphyte.ca/code/live_tree.html > > The plugin handles cleanly deleting nodes for you (there is a callback > that destroys all descendants), so just call node.destroy. > > k > _______________________________________________ > Betternestedset-talk mailing list > Betternestedset-talk at rubyforge.org > http://rubyforge.org/mailman/listinfo/betternestedset-talk >-- Chris O''Connor 718.788.4817 chriso1515 at gmail.com http://www.choipaint.com/ -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/betternestedset-talk/attachments/20070130/f2629872/attachment.html
Krishna Dole
2007-Jan-31 14:53 UTC
[Betternestedset-talk] Noob with trouble getting started with BetterNestedSet
Hey Chris, Try removing the comma from acts_as_nested_set, :scope => :root_id Cheers, k On 1/30/07, Chris O''Connor <chriso1515 at gmail.com> wrote:> Thanks to all for the replies, > > I''ve been on another project and haven''t had time to come back to this, but > now here I am again. > > With a class called ''TreeItem'', (table: ''tree_items''), and simple input from > the console I get this error: > > # from ruby console window > > > >> child = TreeItem.new(:name => "my_computer") > SyntaxError: > ./script/../config/../config/../app/models/tree_item.rb:2: > parse er > ror, unexpected tASSOC, expecting tCOLON2 or ''['' or ''.'' > acts_as_nested_set, :scope => :root_id > ^ > from > C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-1.3.1.584 > 8/lib/active_support/dependencies.rb:204:in > `load_without_new_constant_marking'' > from > C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-1.3.1.584 > 8/lib/active_support/dependencies.rb:204:in `load_file'' > from > C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport- > 1.3.1.584 > 8/lib/active_support/dependencies.rb:343:in > `new_constants_in'' > from > C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-1.3.1.584 > 8/lib/active_support/dependencies.rb:203:in `load_file'' > from > C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-1.3.1.584 > 8/lib/active_support/dependencies.rb:95:in > `require_or_load'' > from > C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport- > 1.3.1.584 > 8/lib/active_support/dependencies.rb:249:in > `load_missing_constant'' > from > C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-1.3.1.584 > 8/lib/active_support/dependencies.rb:453:in `const_missing'' > from > C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-1.3.1.584 > 8/lib/active_support/dependencies.rb:465:in `const_missing'' > from (irb):3 > >> > > My model file: > > #tree_item.rb > > class TreeItem < ActiveRecord::Base > acts_as_nested_set, :scope => :root_id > > end > > my data in mysql from monitor: > > mysql> select * from tree_items; > +----+---------+-----------+------+------+------------------------+ > | id | root_id | parent_id | lft | rgt | name | > +----+---------+-----------+------+------+------------------------+ > | 1 | 1 | NULL | 1 | 2 | ruby | > | 2 | 2 | NULL | 1 | 2 | rails | > | 3 | 3 | NULL | 1 | 6 | computers | > | 4 | 3 | 3 | 2 | 3 | apple | > | 5 | 3 | 3 | 4 | 5 | dell | > | 6 | 6 | NULL | 1 | 8 | rails plug-ins | > | 7 | 6 | 6 | 2 | 3 | better_nested_set | > | 8 | 8 | NULL | 1 | 2 | frameworks | > | 9 | 6 | 6 | 4 | 5 | restful_authentication | > | 10 | 6 | 6 | 6 | 7 | authorization | > | 11 | 11 | NULL | 1 | 2 | databases | > +----+---------+-----------+------+------+------------------------+ > 11 rows in set (0.13 sec) > (you''ll have to trust me I guess)... > > What''s more curious is if I remove the :scope => :root_id I can work with > the console all i like--making new children, saving them and moving them to > others. I can even list the items in a view; however, they are not in the > order I would hope for (due to no scope, yes?). > > Is there something obvious I''m missing? > > Thanks, > Chris > > > > > > On 1/14/07, Krishna Dole < dontfall at gmail.com> wrote: > > > > Hey Chris, > > > > Welcome to the list. I agree we need a nice walk-through tutorial. Our > > code may undergo some changes soon though, so I''m sort of waiting > > until thing settle out before putting it together. > > > > > For example, my migration throws an error when I try to apply the :scope > => > > > :root_id in the model, as shown in the example given at > > > > http://wiki.rubyonrails.org/rails/pages/BetterNestedSet. > > > > What error are you seeing? Remember that you only need a scope if you > > are working with multiple trees. > > > > > > > > If I remove that scope qualification, I can play with it in the console > > > window, and I BELIEVE I understand the creation sequence and methods, > but > > > when it comes to putting together solid scaffolding for this model and > > > actually SHOWING the FULL tree (or even partial trees from a particular > > > node), I get lost quickly. And how does one remove a node cleanly? > > > > It is up to you how you want to display the tree, but as a basic > > example for showing the whole tree: > > @items = SetModel.root.full_set > > then in the view you would loop through @items, and, quoting JCM: "You > > can use style="margin-left:<%= item.level %>em;" in your view to have > > items indented according to their level." (There are performance > > problems with calling #level so many times, but it should get you > > started). > > > > If you want an AJAX tree viewer, LiveTree is a Rails plugin that works > > nicely with nested sets: > > http://www.epiphyte.ca/code/live_tree.html > > > > The plugin handles cleanly deleting nodes for you (there is a callback > > that destroys all descendants), so just call node.destroy. > > > > k > > _______________________________________________ > > Betternestedset-talk mailing list > > Betternestedset-talk at rubyforge.org > > > http://rubyforge.org/mailman/listinfo/betternestedset-talk > > > > > > -- > Chris O''Connor > 718.788.4817 > chriso1515 at gmail.com > http://www.choipaint.com/ > _______________________________________________ > Betternestedset-talk mailing list > Betternestedset-talk at rubyforge.org > http://rubyforge.org/mailman/listinfo/betternestedset-talk > > >