【发布时间】:2016-08-25 09:53:17
【问题描述】:
我正在迭代 stripe charge object,我想总结每天的 amount 总数。
# Returns an array object of charges for a customer
@customer_charges = Stripe::Charge.all(:customer => current_user.stripeid)
观看次数:
<% @customer_charges.map do |c| %>
On Monday, you were charged a total of <%= c.amount %>
<% end %>
当然,上面只是输出每个费用的行,而不是当天的总和。我面临的困难是总结每天的所有费用。有人能指出我正确的方向吗?
输出如下:
"On Monday, you were charged a total of 200000"
"On Tueesday, you were charged a total of 500000"
etc...
代替:
On Monday, you were charged a total of 100000"
On Monday, you were charged a total of 100000"
etc...
我的view 看起来很乱,用if statements 行比较日期,看起来不正确。
【问题讨论】:
-
您应该在这里使用
each而不是map。created是什么?那是一列还是一个方法 -
好的。
created是stripe的json unix时间戳:"created": 1462001409, -
为什么要合计时间戳?这对我来说毫无意义。如果您需要它们作为日期,
Time.at(timestamp)将转换。 -
打错字了。我已经纠正了。我需要的数量
-
这样更好。我仍然认为
map在这里是一个错误。你试过each吗?您可能想使用Time.at(c.created).strftime('%A')来获取星期几,而不仅仅是每个星期都包含“星期一”。
标签: ruby-on-rails ruby ruby-on-rails-4 stripe-payments