Created
May 18, 2017 19:55
-
-
Save kevinchugh/ce97de35e21814730859527584068834 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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