Reputation: 67
i have this:
<% @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 %>
I want to get data like this:
Thank you
Upvotes: 1
Views: 75
Reputation: 2201
You need to wrap each cell in <td>
& </td>
. Drop the <br>
tags, they create new lines, not new cells.
Basically, inside your loop, you create a <tr>
to make your row, then <td>SOME DATA</td>
for each cell, then close the </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 %>
Upvotes: 0
Reputation: 582
Have you looked at in_groups_of
? From the API Array Methods
If I understand you question, this should do the trick!
Upvotes: 1
Reputation: 48626
Use each_with_index instead of each. This way, you can also get the index, like 1,2,3.. and do whatever you want with it.
http://www.ruby-doc.org/core/classes/Enumerable.html#M001511
Upvotes: 0