Hi, I am trying to show pictures (adverts) in a grid. I want to show 3 pictures across and 3 pictures down. How would I do this. Here is my view code: <table cellpadding="5" cellspacing="0"> <tr> <% for advert in @userAdverts %> <td> <%= image_tag url_for_file_column(advert, "image","thumb") unless url_for_file_column(advert, "image","thumb").nil?%> <br><span class="ListTitle"><b><%= link_to h(advert.title), :action => ''show'', :id => advert %></b></span><br /> <%= h(truncate(advert.description, 80)) %> <br> <strong><%= sprintf("$%0.2f", advert.price)unless advert.price=0.0%></strong> </td> <% end %> </tr> </table> -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
David Smit wrote:> Hi, > > I am trying to show pictures (adverts) in a grid. I want to show 3 > pictures across and 3 pictures down. How would I do this. > > Here is my view code: > > <table cellpadding="5" cellspacing="0"> > <tr> > <% for advert in @userAdverts %> > <td> > <%= image_tag url_for_file_column(advert, "image","thumb") > unless url_for_file_column(advert, "image","thumb").nil?%> > > <br><span class="ListTitle"><b><%= link_to h(advert.title), > :action => ''show'', :id => advert %></b></span><br /> > <%= h(truncate(advert.description, 80)) %> > <br> > <strong><%= sprintf("$%0.2f", advert.price)unless > advert.price=0.0%></strong> > </td> > > <% end %> > </tr> > </table>If you on edge (I think it only edge) Array#in_groups_of is your friend http://caboo.se/doc/classes/ActiveSupport/CoreExtensions/Array/Grouping.html#M004481 <table> <% @items.in_groups_of(3).each do |item_group| %> <tr> <% item_group.each do |item| %> <%= item.title %> <% end %> </tr> <% end %> </table> -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---