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).
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).
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?
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 .