[Rails] Synthesizing a debug display from an action?

Tim Bates tim at bates.id.au
Fri Nov 12 06:54:07 GMT 2004


Gavin Sinclair wrote:
> Can this outcome be easily achieved (without creating a view)?

The debug helper implements it like this:

def debug(object)
   begin
     Marshal::dump(object)
     "<pre class='debug_dump'>" +
     "#{h(object.to_yaml).gsub("  ", "&nbsp; ")}" +
     "</pre>"
   rescue Object => e
     # Object couldn't be dumped, perhaps because of singleton methods
     # -- this is the fallback
     "<code class='debug_dump'>#{h(object.inspect)}</code>"
   end
end

Note that it uses the h() method, which comes from ERb::Util -
   require 'erb'

Tim.

-- 
Tim Bates
tim at bates.id.au


More information about the Rails mailing list