我假設你的意思是這樣的:
你有三種型號:
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
比你可以在這樣的ERB視圖建一個表:
<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
什麼你的意思是'動態繪製這樣的表格'。想用Ajax做點什麼嗎?現在您的問題與RoR – jigfox 2010-06-30 13:13:24
無關首先,感謝您編輯我的帖子,該桌現在看起來像一張桌子。 「動態畫這樣的桌子」可能確實是不幸的措辭。我只是想遍歷一個集合。我需要一個建議,如何準備這樣的集合,以基於列的風格在視圖中遍歷它。 – socjopata 2010-06-30 13:21:19