我有三个这样的模型
class Region < ActiveRecord::Base
attr_accessible :region_name
has_many :districts, dependent: :destroy
end
class District < ActiveRecord::Base
attr_accessible :district_name, :region_id
belongs_to :region
has_many :counties, dependent: :destroy
end
class County < ActiveRecord::Base
attr_accessible :county_name, :district_id
belongs_to :district
has_many :subcounties, dependent: :destroy
end
我想在表格中显示这些数据,这样我就有三列地区、地区和县。这样一个地区的所有区和一个区的所有县都在各自的列中显示。
我尝试过这样的事情,但没有奏效
<table>
<tr>
<th>Region</th>
<th>District</th>
<th>County</th>
</tr>
<% @regions.each do |region|%>
<tr>
<td><%=region.region_name%></td>
<td><%=region.districts%></td>
<td><%=region.districts.counties%></td>
</tr>
<%end%>
</table>
我将如何正确地做到这一点?