Skip to content

Instantly share code, notes, and snippets.

@mgreenly
Created March 18, 2011 16:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mgreenly/876350 to your computer and use it in GitHub Desktop.
Save mgreenly/876350 to your computer and use it in GitHub Desktop.
recursively walk association.accessor chain and return the result
def render(object)
receiver = object
accessors = accessor.split(".")
while accessor = accessors.shift
if receiver.class.reflect_on_association(accessor.to_sym)
receiver = receiver.send(accessor)
else
return receiver.send(accessor)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment