Jason  Vogel wrote:
> Source A :
>
> if (@product_coverages != nil && @product_coverages.length > 0)
>       @product_coverages = @product_coverages.each do
> |product_coverage|
>         product_coverage.external_description =
> Coverage.find(product_coverage.coverage_id).external_description # test
>         if (product_coverage.external_description != nil)
>           product_coverage.external_description.capitalize!
>         end
>       end
>     end
>
> Source B :
>
> if (@product_coverages != nil && @product_coverages.length > 0)
>       @product_coverages = @product_coverages.each do
> |product_coverage|
>         product_coverage.external_description =
> Coverage.find(product_coverage.coverage_id).external_description # test
>         return "" if product_coverage.external_description.nil?
>         product_coverage.external_description.capitalize!
>       end
>     end
>
> I wanted to use Source B, but it return "" everytime.  But Source A
> works.  I expected both of them to work.
>
> Jason

if @product_coverages != nil
  @product_coverages.each { |p_c|
    p_c.external_description =
      Coverage.find(p_c.coverage_id).external_description and
      p_c.external_description.capitalize!
  }
end

-------------

A simpler way.  When a description that's nil is encountered,
replace it with "".

if @product_coverages != nil
  @product_coverages.each { |p_c|
    p_c.external_description =
      (Coverage.find(p_c.coverage_id).external_description or "").
      capitalize
  }
end