Rails 4 Sum by Model Method

后端 未结 4 1208
夕颜
夕颜 2021-02-13 02:07

In my app, I have a User model, with a goal_ytd method, which performs some calculations.

In a controller, I have a variable @users

4条回答
  •  说谎
    说谎 (楼主)
    2021-02-13 02:45

    I like to use a combination of map and sum

    @users.map(&:goal_ydt).sum
    

提交回复
热议问题