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
Type 2
0 materials defined
Type 3
4 materials defined
Material 3
Material 4
Material 5
Material 6
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!
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 ?
<% 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?