请问是否可以知道如何在下面的代码中使用哈希显示:user_id,:player_id和:amount属性?
目前创建的数组返回player_id作为键,并返回值{1695 => 100,1714 => 200},而我需要像{1695 => {:user_id,100}这样的东西?
控制器中的代码如下:
@duplicates = Bid.select(:player_id, :user_id, :amount).group(:player_id).having("count(*) > 1").maximum(:amount)视图中的代码:
<div class="col-sm-3" style="background-color:white;"> <%= @duplicates %><br> </div>Please would it be possible to know how to display the :user_id, :player_id and :amount attributes together in a hash from the below code?
At the moment the array created returns player_id as the key and amount as the value {1695=>100, 1714=>200} whereas I need something like {1695=>{:user_id,100}?
The code in the controller is as follows:
@duplicates = Bid.select(:player_id, :user_id, :amount).group(:player_id).having("count(*) > 1").maximum(:amount)The code in the view:
<div class="col-sm-3" style="background-color:white;"> <%= @duplicates %><br> </div>最满意答案
我将在主帖的评论中添加我们提出的答案:
@duplicates = Bid. select("player_id, user_id,MAX(amount)"). group(:player_id). having("count(*) > 1")现在根据您的用例装饰结果:
@duplicates.map! do |rec| { rec. player_id => [ rec.user_id, rec.amount ] } endI am going to add the answer which we came up from the conversations in comments of the main post:
@duplicates = Bid. select("player_id, user_id,MAX(amount)"). group(:player_id). having("count(*) > 1")Now decorate the result as per your usecase:
@duplicates.map! do |rec| { rec. player_id => [ rec.user_id, rec.amount ] } end更多推荐
发布评论