73af4fece11ee3767dc13e89cdc08500

I have 6 items in a row. The 6th item needs not a right margin otherwise only 5 will show in a row.

I feel like I accomplished that... in fact I have. I think there may be a better way to do this though. Any takers?

(edited for nomenclature at 12:46 pst)

- @media.in_groups_of(6, false) do |group|
    .row
      = render :partial => 'media/media', :object => group[0] unless group[0].blank?
      = render :partial => 'media/media', :object => group[1] unless group[1].blank?
      = render :partial => 'media/media', :object => group[2] unless group[2].blank?
      = render :partial => 'media/media', :object => group[3] unless group[3].blank?
      = render :partial => 'media/media', :object => group[4] unless group[4].blank?
      = render :partial => 'media/media', :locals => {:class_hook => 'no_right_margin'}, :object => group[5] unless group[5].blank?

Refactorings

No refactoring yet !

F551cba44a3c386bf61d6b4d6964b23b

Jeffrey Chupp

June 11, 2009, June 11, 2009 13:09, permalink

2 ratings. Login to rate!

I haven't tested this, but it should work (perhaps with minor adjustments)

- @media.in_groups_of(6, false) do |group|
  .row
    - group.each_with_index do |item, index|
      = render :partial => 'media/media', :locals => (index == 5 ? {:class_hook => 'no_right_margin'} : {}), :object => item unless item.blank?
6cb63e2304cb64236520d0e3e353c9bc

dive.myopenid.com

June 22, 2009, June 22, 2009 18:59, permalink

No rating. Login to rate!

maybe have something like

= render first block 5 times, iterate from 0 to 5
= render last and special case

leaving you with 2 lines, instead of 6 or 1,
so that the two cases are easy to distinguish visually?

I just don't like too much logic in one line ...

Your refactoring





Format Copy from initial code

or Cancel