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 --~--~---------~--~----~------------~-------~--~----~ 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-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
dblack-TKXtfPMJ4Ozk1uMJSBkQmQ@public.gmane.org
2007-Jan-29 12:53 UTC
Re: The sum of the values
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 (http://www.manning.com/black) (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) --~--~---------~--~----~------------~-------~--~----~ 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-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 On 1/29/07, dblack-TKXtfPMJ4Ozk1uMJSBkQmQ@public.gmane.org <dblack-TKXtfPMJ4Ozk1uMJSBkQmQ@public.gmane.org> wrote:> > > 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 (http://www.manning.com/black) > (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) > > > >--~--~---------~--~----~------------~-------~--~----~ 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-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---