<% if @base_coverages != nil %> <% if @base_coverages.length > 0 %> <table> <% @base_coverages.each do |i| %> <tr class="<%= cycle("even","odd") %>"> <td><%= i.coverage_id %></td> <td><%= i.external_description %></td> </tr> <% end %> </table> <% end %> <% end %> - Base coverages may be nil - Base coverages may have a length of 0 How do I clean this code up? Thanks, Jason --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Rimantas Liubertas
2006-Dec-05 16:17 UTC
Re: This looks wrong, but it works... what is right way?
2006/12/5, Jason Vogel <jasonvogel-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>:> > <% if @base_coverages != nil %> > <% if @base_coverages.length > 0 %> > <table> > <% @base_coverages.each do |i| %> > <tr class="<%= cycle("even","odd") %>"> > <td><%= i.coverage_id %></td> > <td><%= i.external_description %></td> > </tr> > <% end %> > </table> > <% end %> > <% end %> > > - Base coverages may be nil > - Base coverages may have a length of 0 > > How do I clean this code up?How about this (not much different): <% if !@base_coverages.blank? %> <table> <% @base_coverages.each do |i| %> <tr<%= cycle('' class="odd"'','''') %>> <td><%= i.coverage_id %></td> <td><%= i.external_description %></td> </tr> <% end %> </table> <% end %> Regards, Rimantas -- http://rimantas.com/ --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Alan Francis
2006-Dec-05 16:28 UTC
Re: This looks wrong, but it works... what is right way?
Jason Vogel wrote:> <% if @base_coverages != nil %> > <% if @base_coverages.length > 0 %> > <table> > <% @base_coverages.each do |i| %> > <tr class="<%= cycle("even","odd") %>"> > <td><%= i.coverage_id %></td> > <td><%= i.external_description %></td> > </tr> > <% end %> > </table> > <% end %> > <% end %> > > - Base coverages may be nil > - Base coverages may have a length of 0 > > How do I clean this code up? > > Thanks, > Jason@base_coverages ||= [] would take care of the nil case. You may actually be able to use base_coverages.blank? which I think works as expected for nil, empty strings, empty arrays etc etc You could pull the <table> into a partial and end up with <%= render :partial => "coverages" if !@base_coverages.blank? %> -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Rimantas Liubertas
2006-Dec-05 17:12 UTC
Re: This looks wrong, but it works... what is right way?
<...>> You could pull the <table> into a partial and end up with > > <%= render :partial => "coverages" if !@base_coverages.blank? %>Good idea. I''d change a bit: <%= render :partial => "coverages" unless @base_coverages.blank? %> Regards, Rimantas -- http://rimantas.com/ --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---