Skip to content

Instantly share code, notes, and snippets.

@dimianstudio
Forked from jinleileiking/gist:547099
Created December 10, 2010 13:57
Show Gist options
  • Save dimianstudio/736218 to your computer and use it in GitHub Desktop.
Save dimianstudio/736218 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