This post originated from an RSS feed registered with Ruby Buzz
by Eric Hodel.
Original Post: render_tree for Rails
Feed Title: Segment7
Feed URL: http://blog.segment7.net/articles.rss
Feed Description: Posts about and around Ruby, MetaRuby, ruby2c, ZenTest and work at The Robot Co-op.
Spelunking deep in unfamiliar Rails view code? Flushing out the cobwebs and updating your code? Don't know what gets rendered when?
I have a solution for you:
class ActionView::Base
alias plain_render render
RENDERS = [:partial, :template, :file, :action, :text, :inline, :nothing,
:update]
def render(*args)
@level ||= 0
print ' ' * @level
case args.first
when String then
p args.first
when Hash then
hash = args.first
found = hash.keys & RENDERS
if found.length == 1 then
puts "%p => %p" % [found.first, hash[found.first]]
else
raise "Dunno: %p" % [hash]
end
else
raise "Dunno: %p" % [args]
end
@level += 1
result = plain_render(*args)
@level -= 1
result
end
end
Drop that in test/render_tree.rb and require it in your tests when you want to see a tree like this: