【问题标题】:Rails grape api send hash and use present method togetherRails 葡萄 api 发送哈希和一起使用 present 方法
【发布时间】:2017-03-01 15:42:36
【问题描述】:

我遇到了 Grape::API 的问题。我需要向服务器发送所有找到的运动中心的哈希值:

 { :total => total_found }

并使用一起存在的方法

present sport_centers, :with => API::APISportCenterBasic

我不知道该怎么做。

我在这里需要total_found,因为我只向其他服务器发送了有限数量的运动中心,而且我需要一个总数。

【问题讨论】:

    标签: ruby-on-rails grape-api


    【解决方案1】:

    你可以使用API::APISportCenterBasic.represent sport_centers, total: total_found

    现在你可以在presenter中使用total,添加:

    expose 'total' do |_obj, options|
      options[:total]
    end
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-08-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多