【问题标题】:Rails ignoring/overwriting params passed in body of json requestRails忽略/覆盖json请求正文中传递的参数
【发布时间】:2014-10-16 11:25:04
【问题描述】:

使用 rails 4.1.4

我正在发送帖子请求:

curl -X POST -H "Accept:application/json" -H "Content-Type:application/json" -H "Cache-Control:no-cache" -H "Postman-Token:872ae843-bc12-8194-5984-ab2534fa9872" -d '{
  "car" : {
    "car_brand" : 1,
    "car_model" : 1,
    "car_version" : 1,
    "name" : "first car"
  }
}' http://0.0.0.0:3000/api/car_groups/1/cars

我的路线中的端点:

resources :car_groups, only: :none do
  resources :cars, only: [:index, :show, :create, :update, :destroy]
end

这是我的服务器看到的:

在 url 中传递的参数按原样列在参数中。

在发送带有空正文的请求时,当我检查参数时,答案看起来是一样的:

> {"action"=>"create", "controller"=>"api/v1/cars", "car_group_id"=>"1", "car"=>{}, "format"=>"json", "auth_token"=>nil}

我可能缺少什么?

【问题讨论】:

    标签: ruby-on-rails api rest ruby-on-rails-4.1


    【解决方案1】:

    问题与使用 mimetype 的版本控制 API 有关

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-06-01
      • 1970-01-01
      • 1970-01-01
      • 2020-01-17
      • 2023-03-27
      • 2017-06-25
      • 2012-07-18
      相关资源
      最近更新 更多