Skip to content

Instantly share code, notes, and snippets.

@mwerner
Created July 10, 2012 19:24
Show Gist options
  • Save mwerner/3085657 to your computer and use it in GitHub Desktop.
Save mwerner/3085657 to your computer and use it in GitHub Desktop.
Display all attributes and link any associations
resource.attributes.each_pair do |key, value|
associations = resource.class.reflect_on_all_associations.map &:name
content_type = key[0..(key.index('_id') || -1)-1].to_sym
return value unless associations.include?(content_type)
association = resource.send(content_type)
link_to(association, [:admin, association])
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment