Hai i am creating a json file with my data and i need to calculate the hours before i save it into the database
I am assigning that hash into a variable payload and tried doing this but it returns me an error TypeError (no implicit conversion of Symbol into Integer):
total_hours = @payload.sum{|activity| activity[:hours].to_f}
Hash before converting to json
{:activities=>
[{:project=>1,
:activity=>"my activity",
:hours=>0.2e1,
:date=>Sat, 10 Aug 2019 00:00:00 UTC +00:00},
{:project=>2,
:activity=>"Tester",
:hours=>0.2e1,
:date=>Thu, 01 Aug 2019 00:00:00 UTC +00:00},
{:project=>2,
:activity=>"Tester",
:hours=>0.3e1,
:date=>Thu, 01 Aug 2019 00:00:00 UTC +00:00}]}
I need to sum the hours of my array which is inside the hash. Thanks
total_hours = @payload[:activities].sum{|activity| activity[:hours].to_f}[:activities]is array of obj.