Created
November 5, 2015 21:22
-
-
Save danjohnson3141/61f5c5be5dd6683a64bf to your computer and use it in GitHub Desktop.
Strange Relations
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
module Relations | |
extend ActiveSupport::Concern | |
included do | |
def show_dependents | |
output = [] | |
dependents.each do |dependent| | |
output << { dependent.to_s.titleize => self.send(dependent.to_s).size } | |
end | |
output | |
end | |
def dependents | |
klass = self.class.class_name.constantize | |
klass.reflect_on_all_associations(:has_many).map(&:name) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment