Group By - but showing all the groups

I know this must be easy but I can not see it. I have a table with types of material and a second table of the materials. So;

MaterialType has_many :materials

and

Material belongs_to :material_type

I want to display the list of materials as types and include the types that have no materials, to show;

Type 1   2 materials defined     Material 1     Material 2   <link to add new Type 1 material> Type 2   0 materials defined   <link to add new Type 2 material> Type 3   4 materials defined     Material 3     Material 4     Material 5     Material 6   <link to add new Type 3 material> Etc

The problem is I can show the materials types that have materials defined but I can not work out how to show all the types especially the ones without materials, so I can include the link to add one!

Thanks in advance

The problem is I can show the materials types that have materials defined but I can not work out how to show all the types especially the ones without materials, so I can include the link to add one!

Isn't it a case of doing MaterialType.find :all and then iterating over that list ?

Fred

I know this must be easy but I can not see it. I have a table with types of material and a second table of the materials. So;

MaterialType has_many :materials

and

Material belongs_to :material_type

I want to display the list of materials as types and include the types that have no materials, to show;

This might be helpful -

Sorted it out using interations

<% @material_types.each do |mt| %>             <h2> <%= mt.name %> </h2>             <p>Number of <%= mt.name %> types: <%= Material.find(:all, :conditions => {:material_type => mt.material}).count %> </p>             <% if Material.find(:all, :conditions => {:material_type => mt.material}).count > 0 %>                 <table class="info" border="0" cellpadding="5" cellspacing="1">                   <tr class="header">                    <th>No</th> <th>Name</th> <th>Moisture</th> <th>Dose Size</th> <th>Content</th> <th>MATERIAL EDITOR</th>                   </tr>                   <% Material.find(:all, :conditions => {:material_type => mt.material}).each do |mat| %>                       ..list all the materials

It works! But this does feel like RAILS solutions, does anyone know how to put the Material.find stuff in the controller and just call the .each and .count methods?