Html 将表合并到单个表
相关片段 Show.html.erbHtml 将表合并到单个表,html,css,ruby-on-rails,ruby-on-rails-3,erb,Html,Css,Ruby On Rails,Ruby On Rails 3,Erb,相关片段 Show.html.erb <% outbound_messages.each do |outbound_message| %> <h5>Outbound Message</h5> <%= render "trace/display_tabular_data", :data => outbound_message %> <% end %> 你知道我该怎么做吗?Display_t
<% outbound_messages.each do |outbound_message| %>
<h5>Outbound Message</h5>
<%= render "trace/display_tabular_data", :data => outbound_message %>
<% end %>
你知道我该怎么做吗?Display_tabular_数据在show.html.erb中的不同位置被调用至少15次,因此,如果只在Display_tabular_数据中进行更改,而不在show.html.erb中进行更改,以某种方式获得最终结果,将更加容易。如果不可能,请给我最好的方法?如果您不想为每个对象呈现单独的表,那么在show.html.erb中使用类似的方法如何:
<% unless outbound_messages.empty? %>
<%= render 'trace/display_tabular_data', :data => outbound_messages %>
<% end %>
出站消息%>
然后在部分:
<h5>Outbound Messages</h5>
<table border="1px solid black">
<thead>
<tr>
<% data.first.each do |key,value| %>
<th><%=key.capitalize%></th>
<% end %>
</tr>
</thead>
<% data.each do |outbound_message| %>
<tr>
<% outbound_message.each do |key,value|%>
<td><%=value%></td>
<% end %>
</tr>
</table>
出站消息
只有当您确信每个出站消息都有相同的密钥集时,这才有效。给您
<% if outbound_messages.count > 0 %>
<h5>Outbound Message</h5>
<table border="1px solid black">
<thead>
<tr>
<td>Message ID</td>
<td>Exchange</td>
<td>Relayed</td>
</tr>
</thead>
<% outbound_messages.each do |outbound_message| %>
<tr>
<td>
<%= outbound_message[:message_id] %>
</td>
<td>
<%= outbound_message[:exchange] %>
</td>
<td>
<%= outbound_message[:relayed] %>
</td>
</tr>
<% end %>
</table>
<% end %>
0%>
出栈消息
消息ID
交换
转播
您可以完全消除部分您的'show.html.erb'中的代码重复两次。这是故意的吗?每个出站消息都有相同的密钥集吗?@Charles-是的,每个出站消息都有相同的密钥集。点击图片链接获得一个示例结果。几天前我最初的方法是这样的,但是有太多的键无法像这样键入。我有出站消息、订单、预订等,因此这种方法不起作用。这正是我的想法,但这也需要在show.rb中进行更改。不过,这是一个非常好的解决方案。您必须更改show.html.erb以实现所需的功能,即在表中为outbound_messages集合中的每个对象创建一个新的单行。但是,如果您希望最小化对show.html.erb的影响,你可以将整个outbound_messages集合传递到partial,而不仅仅是一条记录。我肯定会做第二条记录……我应该在我几乎完成应用程序之前考虑一下,而不是现在。不过还是谢谢你。
<h5>Outbound Messages</h5>
<table border="1px solid black">
<thead>
<tr>
<% data.first.each do |key,value| %>
<th><%=key.capitalize%></th>
<% end %>
</tr>
</thead>
<% data.each do |outbound_message| %>
<tr>
<% outbound_message.each do |key,value|%>
<td><%=value%></td>
<% end %>
</tr>
</table>
<% if outbound_messages.count > 0 %>
<h5>Outbound Message</h5>
<table border="1px solid black">
<thead>
<tr>
<td>Message ID</td>
<td>Exchange</td>
<td>Relayed</td>
</tr>
</thead>
<% outbound_messages.each do |outbound_message| %>
<tr>
<td>
<%= outbound_message[:message_id] %>
</td>
<td>
<%= outbound_message[:exchange] %>
</td>
<td>
<%= outbound_message[:relayed] %>
</td>
</tr>
<% end %>
</table>
<% end %>