Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save kevinchugh/ce97de35e21814730859527584068834 to your computer and use it in GitHub Desktop.
Save kevinchugh/ce97de35e21814730859527584068834 to your computer and use it in GitHub Desktop.
# in organization.rb:
def self_and_descendants
# simply return them in the order they should appear in the tree
answer = []
answer << self
answer += Organization.where(parent_organization_id: self.id).
sort_by{|x| x.description}.self_and_descendants # may have to use authorized instead of .all
end
def generation
# what generation are you, this will be how many spaces to prepend
answer = 0
if parent
answer += 1
answer += parent.generation
end
end
# then in the view just add the number of spaces
<% current_user.current_organization.self_and_descendants.each do |o| %>
<option>
<%=o.generation.times.each do %>
-
<%end%>
<%= o.description %>
</option>
<% end %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment