How about in the controller:

@administrators = Administrator.find(:all).in_groups_of(2)

Then in your haml

= render :partial => 'administrator', :collection => @administrators

And in your _administrator.html.haml

%tr
   = render :partial => 'admin_cell', :locals => {:admin =>  
administrator[0]}
   = render :partial => 'admin_cell', :locals => {:admin =>  
administrator[1]}

And then in _admin_cell.html.haml

%td
   = admin.full_name
   %br/
   = mailto admin.email


On Nov 30, 2007, at 8:20 PM, Nathan Weizenbaum wrote:

>
> Well, a direct translation of your RHTML would be
>
>   @administrator.each_with_index do |administrator, i|
>     = "<tr>" if i % 2 == 0
>     %td
>       = administrator.full_name
>       %br/
>       = mail_to administrator.email
>     = "</tr>" if i % 2 == 0
>
> which works, but doesn't indent within the <tr>s. A nicer solution  
> would
> be to define a helper:
>
>   def tr_if(cond, &block)
>     if cond
>       open("tr", &block)
>     else
>       block.call
>     end
>   end
>
> Then you could make your template
>
>   @administrator.each_with_index do |administrator, i|
>     - tr_if i % 2 == 0 do
>       %td
>         = administrator.full_name
>         %br/
>         = mail_to administrator.email
>
> - Nathan
>
> Doug wrote:
>> With a list of ActiveRecord objects, is there a way in HAML to output
>> one cell per iterated object, and two per table row?  Something
>> equivalent to this in RHTML:
>>
>>     <% @administrator.each_with_index do |administrator, i| %>
>>       <%= "<tr>" if i % 2 == 0 %>
>>         <td>
>>           <%= administrator.full_name %>
>>           <br/>
>>           <%= mail_to administrator.email %>
>>         </td>
>>       <%= "</tr>" unless i % 2 == 0 %>
>>
>> I've fought with this for a while with no luck.  Any input would be
>> greatly appreciated!
>>>
>>
>>
>
>
> >


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Haml" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/haml?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to