Forum: Ruby on Rails how i add the sum in too this field

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
5f7237cddd15ab4ea3b1d08aad42f333?d=identicon&s=25 Nopp Deew (poloman)
on 2009-02-19 14:04
    <th>Day work</th>
    <th>Work time/Day</th>

  <% for shift in @shifts %>
  <td><%= '%a' %> <%= '%d/%m/%Y'
  <td><%= time_ampm shift.start %></td>
  <td><%= time_ampm shift.end %></td>
  <td><%= (shift.end - shift.start)/100 %></td>

now I want to add the sum of Work time/Day in to new field when i create

what is that command
80e4cb97cae5c8d745f72337d93fd8f2?d=identicon&s=25 MaD (Guest)
on 2009-02-19 14:18
(Received via mailing list)
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
puts sum
40db9e75b3f5899258e3bdc0c9210154?d=identicon&s=25 Conrad Taylor (Guest)
on 2009-02-19 14:30
(Received via mailing list)
On Thu, Feb 19, 2009 at 5:17 AM, MaD <> wrote:

> puts sum
Also, you should be able to do the following:

sum = rows.inject(0) { | sum, row | sum + row.value }

Good luck,

5f7237cddd15ab4ea3b1d08aad42f333?d=identicon&s=25 Nopp Deew (poloman)
on 2009-02-19 14:37
Attachment: untitled.PNG (7 KB)
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 .
This topic is locked and can not be replied to.