Thanks Guys, that's much more Ruby like code!
--
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-t
On Wed, Apr 1, 2009 at 9:16 AM, Tom Harvey
wrote:
>
> I was doing this:
>
> @line_items = LineItems.find_all_by_invoice_id(params[:id])
> @payments = Payments.find_all_by_invoice_id(params[:id])
>
> �...@total = @line_items.sum{ |item| item.cost }
> �...@payment_total = @payments.sum{
All you need to do to your original code is add a condition to make
sure @payments is not null:
@payment_total = @payments.sum{ |payment| payment.value } unless
@payments.nil?
Or can payment.value be nil for some payments but not others? Inject
could help in that case:
@payment_totals = @payments
3 matches
Mail list logo