我有这个代码,它从table_reward中检索数据,假设要检索等于或低于50分的奖励。这是代码:
def index
@user = User.find_by_id(1)
user_point = @user.point
@rewards = Reward.all
@final = @rewards.each_with_object({}) do |reward, points|
points[reward[:id]] = reward[:point] < user_point
end
@http_status = 200
@http_response[:status] = true
@http_response[:results] = @final
render :json => @http_response.to_json, :status => @http_status
end
这就是结果:
问题是,它应该只显示低于或等于50分的每个奖励的数据而不是所有的奖励。