# Newbie Question

**URL:** <https://discuss.rubyonrails.org/t/newbie-question/9253>\
**Category:** rubyonrails-talk\
**Created:** [February 24, 2007, 9:12am UTC](https://discuss.rubyonrails.org/t/newbie-question/9253 "2007-02-24T09:12:27Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Juan\_Roberto\_Morales](https://avatars.discourse-cdn.com/v4/letter/j/f1d935/32.png) [@Juan\_Roberto\_Morales](https://discuss.rubyonrails.org/u/Juan_Roberto_Morales)\
**Post date:** [February 24, 2007, 9:12am UTC](https://discuss.rubyonrails.org/t/newbie-question/9253/1 "2007-02-24T09:12:27Z")

</div>

Hey guys, I have a pretty much noob question here.

I’m having problems adding values that come from a database, for example if I have several orders in the database, and they have their amounts I can add them using something like

```
@outstanding = @bill.find_all_by_status('1').sum {|bill| bill.amount}

```

and it works properly.

However, there are some instances where I would just like to add certain values however everytime I want to do something like this

@outstanding += @bill.amount

It doesn’t work properly. It gives me a nil + error.

I’m sure you’ve all gone through this before. If someone could help me out, would be great.

---

<div class="post-metadata">

**Author:** ![Juan\_Roberto\_Morales](https://avatars.discourse-cdn.com/v4/letter/j/f1d935/32.png) [@Juan\_Roberto\_Morales](https://discuss.rubyonrails.org/u/Juan_Roberto_Morales)\
**Post date:** [February 25, 2007, 7:05am UTC](https://discuss.rubyonrails.org/t/newbie-question/9253/2 "2007-02-25T07:05:29Z")

</div>

Nick:

Thanks for the reply.

The problem I’m getting is that say I initialize it to 0 or 0.0 since it’s a float. I’m still getting the same issue.

It’s weird, could you or anyone else show me a working sample of this?

I’ve tried doing this

@outstanding = 0 for item in @items if item.status == 1 @outstanding += item.amount end end

and I get an error.

---

<div class="post-metadata">

**Author:** ![Luke\_Ivers](https://avatars.discourse-cdn.com/v4/letter/l/67e7ee/32.png) [@Luke\_Ivers](https://discuss.rubyonrails.org/u/Luke_Ivers)\
**Post date:** [February 26, 2007, 7:42pm UTC](https://discuss.rubyonrails.org/t/newbie-question/9253/3 "2007-02-26T19:42:57Z")

</div>

And you’re sure that item.amount has been initialized? I would suggest using the script/console command to test this out… script/console opens up an IRB window that will allow you access to all of your models… you can do a find statement just like you would in your actual site

outstanding = 0 Bill.find\_by\_status\_id(1).each do |bill| puts outstanding, bill.amount outstanding += bill.amount end And see what the values are when it errors (see if it thinks that outstanding is nil, or bill.amount) If that works perfectly, then you are somehow un-initializing one of these values elsewhere in your application.
