<% if @base_coverages != nil %>
<% if @base_coverages.length > 0 %>
<%= i.coverage_id %> | <%= i.external_description %> |
- Base coverages may be nil
- Base coverages may have a length of 0
How do I clean this code up?
Thanks,
Jason
<% if @base_coverages != nil %>
<% if @base_coverages.length > 0 %>
<%= i.coverage_id %> | <%= i.external_description %> |
How do I clean this code up?
Thanks,
Jason
Jason V. wrote:
<% if @base_coverages != nil %>
<% if @base_coverages.length > 0 %><% @base_coverages.each do |i| %>
<% end %> <% end %>"> <% end %><%= i.coverage_id %> <%= i.external_description %>
- 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
2006/12/5, Jason Vogel [email protected]:
<% 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? %>
<%= i.coverage_id %> | <%= i.external_description %> | <% end %>
<…>
You could pull the
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
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs