作者:mobiledu2502852915 | 来源:互联网 | 2023-05-17 13:50
IhavetwomodelsinRails5andusignPostgres:我在Rails5中有两个模型并且使用Postgres:classSale<Appli
I have two models in Rails 5 and usign Postgres:
我在Rails 5中有两个模型并且使用Postgres:
class Sale
so how can i get sales group by category and sum the total of sales in each category? and how can i show it in my view (in a instance variable). For example i want to show in my view this:
那么我如何才能按类别获得销售组并总计每个类别的销售总额?以及如何在我的视图中显示它(在实例变量中)。例如,我想在我的视图中显示:
CategoryOne : Total $3000 (maybe the result is a hash but how can i show it in the view?
CategoryOne:总计$ 3000(可能结果是哈希,但我怎么能在视图中显示它?
CategoryTwo : Total $4000
CategoryTwo:总计4000美元
CategoryThree : Total $2200
类别3:总计2200美元
and so on....
等等....
which is the right rails way query (active record)? and how to show the results in view? thanks
这是正确的rails方式查询(活动记录)?以及如何在视图中显示结果?谢谢
2 个解决方案