jeudi 8 décembre 2016

create method to calculate sum of column

I have following code in model

def get_points(account)
  return @array if account.nil? || account.exercise != 1

  credit::Helper.apply_points(
    @array,
    'updated_at',
    'minutes',
    'points',
    account.frequency,
    account.points,
    account.schedule,
    account.max_points
  )
end

I did sum of points in json ealier like

(@daily.inject(0){|result,element| result + element.points})

but i want to use this logic in model

how can i create another method in model to do sum of account.points and call method in controller?

Thanks

Aucun commentaire:

Enregistrer un commentaire