# Format Class Name

**URL:** <https://www.ruby-forum.com/t/format-class-name/112308>\
**Category:** Rails\
**Created:** [August 17, 2007, 10:35am UTC](https://www.ruby-forum.com/t/format-class-name/112308 "2007-08-17T10:35:10Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![johnnybutler7](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/8491ac/32.png) [@johnnybutler7](https://www.ruby-forum.com/u/johnnybutler7)\
**Post date:** [August 17, 2007, 10:35am UTC](https://www.ruby-forum.com/t/format-class-name/112308/1 "2007-08-17T10:35:10Z")

</div>

Hi,

I have a loop which loops through all the associations for a particular  
model, what i want is to display a label with the class name formatted  
like “My Class Name”

\<% @project.reflect\_on\_all\_associations.each do |association| %\>  
\<%= association.name %\>  
\<%= association.class.name %\>  
\<% end %\>

The above gives me “my\_class\_name” and the second output gives me  
“MyClassName” but what i want is My Class Name" without the underscore  
and with a space after the capitals. Is there a quick way to this with  
rails or do i need to write a method to handle this?

Any Advice appreciated,

Johnny B
