# The sum of the values

**URL:** <https://www.ruby-forum.com/t/the-sum-of-the-values/83745>\
**Category:** Rails\
**Created:** [January 29, 2007, 1:42pm UTC](https://www.ruby-forum.com/t/the-sum-of-the-values/83745 "2007-01-29T13:42:53Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![swanand\_deodhar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e36b37/32.png) [@swanand\_deodhar](https://www.ruby-forum.com/u/swanand_deodhar)\
**Post date:** [January 29, 2007, 1:42pm UTC](https://www.ruby-forum.com/t/the-sum-of-the-values/83745/1 "2007-01-29T13:42:53Z")

</div>

Hi!  
I want to find sum of values for a particular field of all the  
records. Right nw i m doing it using simple looping mechanism.  
@dummy=0  
@quotations.each do|quotation|@dummy+=quotation.value end  
Is there any other way for doing this??  
Also, when i m using an observer on a dropdown where on selecting  
a  
vendor’s name from it, would result in shwoing the list of quotations  
from  
him. This is working for some vendors only. Wot cud be the problem??  
Thnx and regards,  
Swanand

---

<div class="post-metadata">

**Author:** ![swanand\_deodhar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e36b37/32.png) [@swanand\_deodhar](https://www.ruby-forum.com/u/swanand_deodhar)\
**Post date:** [January 29, 2007, 1:54pm UTC](https://www.ruby-forum.com/t/the-sum-of-the-values/83745/2 "2007-01-29T13:54:56Z")

</div>

Hi –

On Mon, 29 Jan 2007, swanand deodhar wrote:

> Hi!  
> I want to find sum of values for a particular field of all the  
> records. Right nw i m doing it using simple looping mechanism.  
> @dummy=0  
> @quotations.each do|quotation|@dummy+=quotation.value end  
> Is there any other way for doing this??

This should do it:

total = @quotations.sum(:value)

> ```
> Also, when i m using an observer on a dropdown where on selecting a
> 
> ```
> 
> vendor’s name from it, would result in shwoing the list of quotations from  
> him. This is working for some vendors only. Wot cud be the problem??

I can’t tell without some more information.

David

–  
Q. What is THE Ruby book for Rails developers?  
A. RUBY FOR RAILS by David A. Black ([Ruby for Rails](http://www.manning.com/black))  
(See what readers are saying! [http://www.rubypal.com/r4rrevs.pdf](http://www.rubypal.com/r4rrevs.pdf))  
Q. Where can I get Ruby/Rails on-site training, consulting, coaching?  
A. Ruby Power and Light, LLC ([http://www.rubypal.com](http://www.rubypal.com))

---

<div class="post-metadata">

**Author:** ![swanand\_deodhar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e36b37/32.png) [@swanand\_deodhar](https://www.ruby-forum.com/u/swanand_deodhar)\
**Post date:** [January 29, 2007, 2:03pm UTC](https://www.ruby-forum.com/t/the-sum-of-the-values/83745/3 "2007-01-29T14:03:00Z")

</div>

Hi!  
I m hvng a list of vendor’s with me. In the view i hve attached an  
observer to the dropdown of this vendor’s list.  
\<%= observe\_field (:vendor\_name\_id  
:frequency=\>1,  
:update=\>‘ob\_div’,  
:url=\>{:action=\>:quotation}) %\>  
Now, once the user selects a vendor from the dropdown,thn in the  
quotation  
action in controller, i m trying to find out his credit rating and the  
credit period expiry date for the latest order placed with him(with some  
date arithmatic)  
@vendor=Entry.find\_by\_name(request.raw\_post).  
which will populate the ob\_div. This is working for some vendors and not  
all. In the vendor’s table i m hvng the column called as 'credit\_rating"  
Wot cud be wrong?  
Thnx and regards,  
Swanand
