Skip to content

Instantly share code, notes, and snippets.

@jinleileiking
Created August 24, 2010 07:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jinleileiking/547099 to your computer and use it in GitHub Desktop.
Save jinleileiking/547099 to your computer and use it in GitHub Desktop.
class Subject < ActiveRecord::Base
validates_presence_of :name
validates_uniqueness_of :name
acts_as_tree
class << self
@@all_subjects =[]
def get_all_childrens_recursive parent
return if parent == nil
return if parent.children == nil
return if parent.children.empty?
childrens = parent.children
childrens.each do |children|
@@all_subjects <<= children
get_all_childrens_recursive children
end
end
def get_all_childrens
root = self.root
@@all_subjects = []
@@all_subjects <<= root
get_all_childrens_recursive root
@@all_subjects
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment