Skip to content

Instantly share code, notes, and snippets.

@danjohnson3141
Created November 5, 2015 21:22
Show Gist options
  • Save danjohnson3141/61f5c5be5dd6683a64bf to your computer and use it in GitHub Desktop.
Save danjohnson3141/61f5c5be5dd6683a64bf to your computer and use it in GitHub Desktop.
Strange Relations
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