<% for month in @months %>
<%= render(:partial => “month” , :object => month) if month %>
Calendar year, 2006 is only partially complete–the first record is
October 16, 2006. Therefore, I only want rails to render the partial if
month is not nil. @months[0]-@months[8] are nil. However the code
above does not work.
What is the correct code to check and see if the array, month is not a
nil object before rendering the partial?
@months is an array of arrays. Month is that array containing Day
objects. Each Day object is nil in the month arrays in @month for
months 0-8 in the @months corresponding to 2006.
Perhaps you could look at your code that generates and manipulates the
array and arrange for any unused element to always be nil. Or, you
could turn it into an object which has its own ‘hascontent?’
flag/method?
if you say @month.compact! ruby removes any nil elements from the array.
Its great for exactly this purpose.
Since the “if month” test wasn’t working (i.e., it was always
returning true), I’m assuming that the elements Sam wants to skip are
not nil. I think they’re empty arrays, which compact! will not
remove.