Created
July 10, 2012 19:24
-
-
Save mwerner/3085657 to your computer and use it in GitHub Desktop.
Display all attributes and link any associations
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
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