【发布时间】:2018-03-29 14:50:00
【问题描述】:
我有一个带有嵌套属性的表单,现在我想在表格上显示,但我无法打破它作为列交互的行。我能怎么做?我能做什么?
Here's an image of my current table.
<% @salmonella.process_salmonellas.each do |process| %>
<tr align="center">
<td><%= process.title %></td>
<table>
<% process.stages.each do |stage| %>
<tr>
<td><%= stage.title %></td>
<td>
<table>
<% stage.lines.each do |line| %>
<tr>
<td><%= line.material %></td>
<td><%= line.indicator_name %></td>
</tr>
<% end %>
</table>
</td>
</tr>
<% end %>
</table>
</tr>
And this is how it should look like
这或多或少是我在脑海中绘制的表格模板:
<table>
<!-- Each for principal object -->
<tr>
<td><!-- fields of principal object --></td>
<td>
<!-- each nested attributes from principal object and the model -->
<tr>
<td><!-- fields of second object--></td>
<td>
<!-- each from model and another model that is nested too from principal object and model -->
<tr>
<td><!-- fields of third object --></td>
</tr>
</td>
</tr>
</td>
</tr>
</table>
这就是它在我的控制器中的嵌套方式:
def salmonella_params
params.require(:salmonella).permit(:title,
process_salmonellas_attributes: [
:id,
:title,
:_destroy,
stages_attributes: [
:id,
:title,
:_destroy,
lines_attributes:[
:id,
:material,
:indicator_name,
:_destroy
]
]
])
end
【问题讨论】:
-
你的意思是你没有行?原因是因为您只使用
<td>而没有使用<tr>(代表表格行)。如果是这种情况,请快速阅读w3schools.com/html/html_tables.asp -
我尝试输入
<tr>,但它无法识别为<td> -
那是因为您必须将
<td>放在<tr>内(以及<table>内),请观看我发送的链接中的一个示例。 -
3 张桌子?我会更新问题
-
用 3 张桌子搞得一团糟
标签: html css ruby-on-rails