acts_as_list / acts_as_tree / acts_as_nested_set - which one

Rails List wrote:

I am creating forum application which needs usage of acts_as_list or acts_as_tree or acts_as_nested_set.

I am unable to decide among these. please could some one recommend from their experience?

Don't use acts_as_tree -- its data structure is simple but inefficient for querying. Use awesome_nested_set instead. Depending on what you're doing, acts_as_list may be useful as well (and it works in conjunction with awesome_nested_set).

Best,

Marnen Laibow-Koser wrote:

Rails List wrote:

I am creating forum application which needs usage of acts_as_list or acts_as_tree or acts_as_nested_set.

I am unable to decide among these. please could some one recommend from their experience?

Don't use acts_as_tree -- its data structure is simple but inefficient for querying. Use awesome_nested_set instead. Depending on what you're doing, acts_as_list may be useful as well (and it works in conjunction with awesome_nested_set).

Best, -- Marnen Laibow-Koser http://www.marnen.org marnen@marnen.org

Thanks Marnen, I have had a look at awesome_nested_set. It follows the Rails Plugin tradition of not having sufficient tutorial that a beginner can understand. Could you recommend some tutorial for awesome_nested_set?

Craigslist Clone www.railslist.com

It does have a tutorial somewhere in Wiki section of github, as long as I remember.

But all you really need is to install it, declare :lft, :rgt, and :parent_id in the migration, and put act_as_nested_set in the model. Not hard at all. However, note that you should recreate all the existing instances of the model, so that :lft and :rgt fields will be set.

Cheers, Gleb

P.S.: From my code:

class MakePlaylistsNested < ActiveRecord::Migration   def self.up     add_column :playlists, :parent_id, :integer     add_column :playlists, :lft, :integer     add_column :playlists, :rgt, :integer   end

  def self.down     remove_column :playlists, :parent_id, :lft, :rgt   end end

class Playlist < ActiveRecord::Base   acts_as_nested_set :scope => :user_id, :depenendent => :destroy ... end

It does have a tutorial somewhere in Wiki section of github, as long as I remember.

But all you really need is to install it, declare :lft, :rgt, and :parent_id in the migration, and put act_as_nested_set in the model. Not hard at all.

Right.

However, note that you should recreate all the existing instances of the model, so that :lft and :rgt fields will be set.

That's unnecessary. You can just walk the tree and set them appropriately (this is best done in the migration). Or even easier, just call Model.rebuild! . See http://bit.ly/gVr7Q .

Cheers, Gleb

Best,

Rails List wrote:

Are these acts_as_* are external plugins or are they built in with active record?

They're gems and plugins that you'll have to install. I think acts_as_list and acts_as_tree used to be part of AR, but they no longer are.

Best,

Create the item, and then use item.move_to_child_of(parent) method. Manual: http://wiki.github.com/collectiveidea/awesome_nested_set/awesome-nested-set-cheat-sheet