From: "David A. Black" Date: 2005-04-22T06:54:45+09:00 Subject: Re: for .. in .. else? Hi -- On Fri, 22 Apr 2005, Douglas Livingstone wrote: > In my erb templates, I've got this pattern quite often: > > > > <% for aSong in songList %> > > <% end %> > <% unless songList.empty? %> > > <% end %> >
Songs<%= aSong.name %>no songs!
> > Is there any way to write is more like this: > > > > <% for aSong in songList %> > > <% else %> > > <% end %> >
Songs<%= aSong.name %>no songs!
How about (untested): <% if song_list.empty? %> <% else %> <% for song in song_list %> <% end %> <% end %>
Songs
no songs!
<%= song.name %>
(caMelCaSe method and variable name cleansing at no extra charge :-) David -- David A. Black dblack@wobblini.net