2011-04-19 49 views
1

一个记录,我有这样的:数据行和列,在一个单元

<% @devices.each do |device| %> 
<tr> 
<td> 
    <% if device.photo.exists? then %> 
    <%= image_tag device.photo.url(:small) %></br> 
    <% end %> 
    <%= link_to device.name, device %></br> 
    <%= device.description %></br> 
    <%= link_to 'Redaguoti', edit_device_path(device) %></br> 
    <%= link_to 'Ištrinti', device, :confirm => 'Ar tikrai norite ištrinti šį prietaisą?', :method => :delete %> 
</td> 


<% end %> 

我想要得到的数据是这样的:

table

谢谢

回答

1

你有没有看着in_groups_of?从API Array Methods

如果我理解你的问题,这应该做的伎俩!

+0

谢谢,这是我需要的 – 2011-04-20 06:48:11

0

您需要将每个单元格包装到<td> & </td>。删除<br>标签,他们创建新的行,而不是新的单元格。

基本上,你的循环里面,你创建一个<tr>,使您的行,然后<td>SOME DATA</td>每个细胞,然后关闭</tr>

<% @devices.each do |device| %> 
<tr> 
<td> 
    <% if device.photo.exists? then %> 
    <%= image_tag device.photo.url(:small) %></br> 
    <% end %> 
</td> 
<td> 
    <%= link_to device.name, device %> 
</td> 
<td> 
    <%= device.description %> 
</td> 
<td> 
    <%= link_to 'Redaguoti', edit_device_path(device) %> 
</td> 
<td> 
    <%= link_to 'Ištrinti', device, :confirm => 'Ar tikrai norite ištrinti šį prietaisą?', :method => :delete %> 
</td> 
</tr> 

<% end %> 
相关问题