The sum of the values

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

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)
(See what readers are saying! 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)

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