I assume you meant something like this:
You have three models:
class Hostpital < ActiveRecord::Base
has_many :patients
has_many :temp_readings, :through => :patients
end
class Patient < ActiveRecord::Base
belongs_to :hospital
has_many :temp_readings
end
class TempReading < ActiveRecord::Base
belongs_to :patient
end
Than you can create the table in the form of erb as follows:
<table>
<thead>
<tr>
<th> </th>
<%- some_hospital.temp_readings.map(&:date_of_reading).sort do |date_of_reading| -%>
<th><%= date_of_reading %></th>
<%- end -%>
</tr>
</thead>
<tbody>
<%- some_hospital.patients.each do |patient| -%>
<tr>
<th><%= patient.name %></th>
<%- patient.hospital.temp_readings.map(&:date_of_reading).sort do |date_of_reading| -%>
<td><%= patient.temp_reading.find_by_date_of_reading(date_of_reading) %></td>
<%- end -%>
</tr>
<%- end -%>
</tbody>
</table>
, , date_of_reading