Hi, Can somebody give me what could be the structure and content of locations table, if that is to be defined as acts_as_tree? Your help is appreciated and thanks in advance. class Location < ActiveRecord::Base acts_as_tree :order => "location_name" end -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Venu Vallayil wrote:> > Hi, > > Can somebody give me what could be the structure and content of > locations table, if that is to be defined as acts_as_tree? > > > Your help is appreciated and thanks in advance. > > > > class Location < ActiveRecord::Base > acts_as_tree :order => "location_name" > endall you need is a "parent_id" column in the table/model. dat''s it. you''ll gain the following methods: location.ancestors # all parents of object location.root # returns the first first parent in the leaf location.self_and_siblings # the same generation of objects location.siblings # same generation, excluding the location object location.parent # the direct parent of the location object location.children # the direct children of the location object or an empty array if no children exist hth... http://wiki.rubyonrails.org/rails/pages/ActsAsTree -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
> Can somebody give me what could be the structure and content of > locations table, if that is to be defined as acts_as_tree?(( missed the question; the table should be )) table locations ============== id int auto_increment not null parent_id int not null location_name text_or_whatever not null primary key(id) .. (you could also index the parent_id column for added performace sql wise) that should suffice ;) enjoy -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Shai Rosenfeld wrote:>> Can somebody give me what could be the structure and content of >> locations table, if that is to be defined as acts_as_tree? > > > (( missed the question; the table should be )) > > table locations > ==============> > id int auto_increment not null > parent_id int not null > location_name text_or_whatever not null > primary key(id) .. > (you could also index the parent_id column for added performace sql > wise) > > that should suffice ;) > enjoyShai......let me try with your input! I am a "newbie" in ROR Thanks Venu -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---