Reputation: 330
I am trying to put a <div title="Pages">
for every two lines of the code below, else would use instead.
However, i wish to use a <div title="Pages 1-2">
and <div title="Pages 3-4">
and so on.
The code is not right even for the question on the first paragraph as i had tried it.
document_images_list
prints the url of the images. (which is working ok)
<% @print.document_images_list.each do |image| %>
<% if (1..2).each do |pages| %>
<div title="Pages">
<% else %>
<div>
<% end %>
<%= image_tag image %>
</div>
<% end %>
Upvotes: 1
Views: 101
Reputation: 4880
A bit hackish but the following should work:
To simplify the code, let's assume @images = @print.document_images_list
:
<% @images.in_groups_of(2, false).each do |images| %>
<div title="Pages <%= "#{@images.index(images[0]).next}-#{@images.index(images[1]).next}" %>">
<%= image_tag images[0] %>
<%= image_tag images[1] %>
</div>
<% end %>
This will result in:
<div title="Pages 1-2">
<img src="..." />
<img src="..." />
</div>
<div title="Pages 3-4">
<img src="..." />
<img src="..." />
</div>
Which is what you're looking for if I understood correctly.
Upvotes: 0
Reputation: 11876
<% @print.document_images_list.each do |image| %>
<div title="<%= cycle("Pages", "Pages", "")>
<%= image_tag image %>
</div>
<% end %>
try this
Upvotes: 1