<tr> <th>Day work</th> <th>Start</th> <th>End</th> <th>Work time/Day</th> </tr> <% for shift in @shifts %> <tr> <td><%= shift.date.strftime ''%a'' %> <%= shift.date.strftime ''%d/%m/%Y'' %></td> <td><%= time_ampm shift.start %></td> <td><%= time_ampm shift.end %></td> <td><%= (shift.end - shift.start)/100 %></td> </tr> now I want to add the sum of Work time/Day in to new field when i create what is that command -- 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-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
to be honest, i don''t really understand what you are trying to do, but if you just want to build a sum to put it into some field: initialize a variable with 0 (outside of your for-loop) and add any value you want to that variable. sum = 0 rows.each do |row| sum += row.value end puts sum --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On Thu, Feb 19, 2009 at 5:17 AM, MaD <mayer.dominik-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > to be honest, i don''t really understand what you are trying to do, but > if you just want to build a sum to put it into some field: > initialize a variable with 0 (outside of your for-loop) and add any > value you want to that variable. > > sum = 0 > rows.each do |row| > sum += row.value > end > puts sumAlso, you should be able to do the following: sum = rows.inject(0) { | sum, row | sum + row.value } Good luck, -Conrad> > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
from "<%= (shift.end - shift.start)/100 %>" mean work time per day now i want to add the sum of Total work time i to new field i''m newbie for ROR please tell me step by step , thank you . Attachments: http://www.ruby-forum.com/attachment/3317/untitled.PNG -- 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-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 -~----------~----~----~----~------~----~------~--~---