【问题标题】:customize Grape API response自定义 Grape API 响应
【发布时间】:2015-06-12 11:12:14
【问题描述】:

我在我的 rails 应用程序中使用 Grape GEM,如何自定义响应 如果没有找到记录或请求参数有效

@video = Video.where(id: allowed_pa​​rams[:id]).first!

例如没有任何id的记录

【问题讨论】:

    标签: ruby-on-rails grape grape-api


    【解决方案1】:

    你可以这样做:

    @video = Video.where(id: permitted_params[:id]).first!
    if @video
       #your code
    else
      error!({:error_message => "Record Could not found"}, 422)
    end
    

    【讨论】:

      猜你喜欢
      • 2016-07-24
      • 2018-11-08
      • 2018-06-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多