Revision: 24773
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at March 10, 2010 19:09 by inkdeep
Initial Code
%w(1 2 3 4 5 6 7).in_groups_of(3, ' ') {|group| p "<tr>" << (group.collect! {|x| "<td>#{x}</td>" }.to_s) << "</tr>" } # returns: #"<tr><td>1</td><td>2</td><td>3</td></tr>" #"<tr><td>4</td><td>5</td><td>6</td></tr>" #"<tr><td>7</td><td> </td><td> </td></tr>" # The better rails way: <table> <% %w(1 2 3 4 5 6 7).in_groups_of(3, ' ') do |group| %> <%= content_tag(:tr, (group.collect! {|x| content_tag(:td, "#{x} hoo!") } ) ) %> <% end %> </table> # returns: # <table> # <tbody> # <tr><td>1 hoo!</td><td>2 hoo!</td><td>3 hoo!</td></tr> # <tr><td>4 hoo!</td><td>5 hoo!</td><td>6 hoo!</td></tr> # <tr><td>7 hoo!</td><td> hoo!</td><td> hoo!</td></tr> # </tbody> # </table>
Initial URL
Initial Description
Initial Title
Rails in groups of
Initial Tags
rails, ruby
Initial Language
Rails