# Equivalent to ColdFusion's CFDUMP tag in Ruby on Rails?

**URL:** <https://www.ruby-forum.com/t/equivalent-to-coldfusions-cfdump-tag-in-ruby-on-rails/82036>\
**Category:** Ruby\
**Created:** [March 15, 2006, 3:16am UTC](https://www.ruby-forum.com/t/equivalent-to-coldfusions-cfdump-tag-in-ruby-on-rails/82036 "2006-03-15T03:16:49Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [March 15, 2006, 3:16am UTC](https://www.ruby-forum.com/t/equivalent-to-coldfusions-cfdump-tag-in-ruby-on-rails/82036/1 "2006-03-15T03:16:49Z")

</div>

One of ColdFusion’s best features is it’s CFDUMP tag with awesome  
visual representation of data, especially for objects, arrays, etc.  
For PHP there is a class called dBug created by Kwaku Otchere  
([http://dbug.ospinto.com](http://dbug.ospinto.com)). It is basically a port of cfdump to PHP  
with an identical visual style.

So I was wondering … has anyone done this for Ruby on Rails? Or is  
there anything similar?

-Kenric

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [March 15, 2006, 5:25am UTC](https://www.ruby-forum.com/t/equivalent-to-coldfusions-cfdump-tag-in-ruby-on-rails/82036/2 "2006-03-15T05:25:00Z")

</div>

Dont know of anything similar, but you could just:

require ‘yaml’

variable = {  
“first”=\> “1”,  
“second” =\> nil,  
“third”=\> {  
“inner third 1” =\> nil,  
“inner third 2”=\>“yeah”  
},  
“fourth” =\> nil  
}

```
<%= variable.to_yaml %>
```

Not nearly as fancy though 🙂

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [March 15, 2006, 7:15am UTC](https://www.ruby-forum.com/t/equivalent-to-coldfusions-cfdump-tag-in-ruby-on-rails/82036/3 "2006-03-15T07:15:20Z")

</div>

arg… You made me do it. It sucks, but it works for basic types.  
You must use it with an Array or Hash otherwise you get no headers:

class Object  
def to\_html(value = self.to\_s);  
return “#{value}”  
end  
end

class String  
def to\_html; super(self) end  
end

class Symbol  
def to\_html; super(’:’ + self.to\_s) end  
end

class NilClass  
def to\_html; super(‘nil’) end  
end

class Hash  
def to\_html  
html = “

”  
self.each\_pair do |k, v|  
html += “#{k.to\_html}”  
end  
html += “

| #{self.class} |
| #{v.to\_html} |

”  
super(html)  
end  
end

class Array  
def to\_html  
html = “

”  
self.size.times do |index|  
html += “#{index}”  
end  
html += “

| #{self.class} |
| #{self[index]} |

”  
super(html)  
end  
end

variable = {  
“first”=\> “1”,  
:a23 =\> “second”,  
“third”=\> {  
nil =\> “inner third 1”,  
“inner third 2”=\>“yeah”  
},  
:values =\> [1, 2, 3, 4],  
nil =\> “fourth”  
}

Then you can do:

\<%= variable.to\_html %\>

To get output that looks very similar to the dBug stuff for Php. I  
used the styles that were at the link you provided, but I had to change  
up the names to fit better:

 table.RdBug\_Array,table.RdBug\_Object,table.RdBug\_Hash,table.RdBug\_String,table.RdBug\_Symbol { font-family:Verdana, Arial, Helvetica, sans-serif; color:#000000; font-size:12px; } .RdBug\_ArrayHeader, .RdBug\_ObjectHeader, .RdBug\_HashHeader, .RdBug\_StringCHeader, .RdBug\_SymbolHeader { font-weight:bold; color:#FFFFFF; } /\* array \*/ table.RdBug\_Array { background-color:#006600; } table.RdBug\_Array td { background-color:#FFFFFF; } table.RdBug\_Array td.RdBug\_ArrayHeader { background-color:#009900; } table.RdBug\_Array td.RdBug\_ArrayKey { background-color:#CCFFCC; } /\* resource \*/ table.RdBug\_Hash { background-color:#006600; } table.RdBug\_Hash td { background-color:#FFFFFF; } table.RdBug\_Hash td.RdBug\_HashHeader { background-color:#009900; } table.RdBug\_Hash td.RdBug\_HashKey { background-color:#CCFFCC; }

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [March 15, 2006, 11:01am UTC](https://www.ruby-forum.com/t/equivalent-to-coldfusions-cfdump-tag-in-ruby-on-rails/82036/4 "2006-03-15T11:01:55Z")

</div>

> One of ColdFusion’s best features is it’s CFDUMP tag with awesome  
> visual representation of data, especially for objects, arrays, etc.  
> For PHP there is a class called dBug created by Kwaku Otchere  
> ([http://dbug.ospinto.com](http://dbug.ospinto.com)). It is basically a port of cfdump to PHP  
> with an identical visual style.
> 
> So I was wondering … has anyone done this for Ruby on Rails? Or is  
> there anything similar?

\<%=debug the\_object\_you\_want\_to\_inspect %\>

Also, ask Rails questions to the Rails list rather than here; you’ll get  
better answers.

Cheers,  
Dave
