Hi --

On Fri, 22 Apr 2005, Douglas Livingstone wrote:

> In my erb templates, I've got this pattern quite often:
>
> <table>
> <th>Songs</th>
> <% for aSong in songList %>
> <td><%= aSong.name %></td>
> <% end %>
> <% unless songList.empty? %>
> <td>no songs!</td>
> <% end %>
> </table>
>
> Is there any way to write is more like this:
>
> <table>
> <th>Songs</th>
> <% for aSong in songList %>
> <td><%= aSong.name %></td>
> <% else %>
> <td>no songs!</td>
> <% end %>
> </table>

How about (untested):

   <table>
     <tr>
       <th>Songs</th>
     </tr>
     <% if song_list.empty? %>
       <tr>
         <td>no songs!</td>
       </tr>
     <% else %>
       <% for song in song_list %>
         <tr>
           <td><%= song.name %></td>
         </tr>
       <% end %>
     <% end %>
     </tr>
   </table>

(caMelCaSe method and variable name cleansing at no extra charge :-)


David

-- 
David A. Black
dblack / wobblini.net