葡萄API忽略PUT / POST PARAMS [英] grape api ignores PUT/POST params

查看:167
本文介绍了葡萄API忽略PUT / POST PARAMS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我建立了一个Rails应用程序葡萄API。我与RSpec的要求规范测试。制作后的路线是这样,当我遇到的问题:

I am building a grape api for a rails app. I am testing it with rspec request specs. I have encountered the problem when making a post route like this:

resources :events do
  segment '/:event_id' do
    resources :tickets do
       post do
         event = current_user.events.find params[:event_id]
         ...#do sth with event using params[:tickets_ids]

相应的规范:

it "should should return the JSON hash of validated tickets" do
  post "/api/mobile/#{version}/events/#{event.id}/tickets/", { tickets_ids: [1,2] }, credentials
  response.should be_success
  JSON.parse(response.body).should be_kind_of Hash
end

葡萄控制器是不是能看到哪些不被作为URL的一部分的任何PARAMS。当打印出PARAMS [:tickets_ids]是零。使用GET请求时,我没有这个问题。我能够重现手动发送请求时使用curl的问题。嵌套资源路由也是没有问题的,因为它的表现与顶级的路线是一样的。

Grape 'controller' is not able to see any params which are not sent as a part of url. When printing out params[:tickets_ids] it is nil. I do not have this problem when using get requests. I am able to reproduce the issue when sending request manually using curl. Nested resources routing is also not a problem since it behaves the same with top level route.

我发现GitHub上下面的问题,但应用给猴子补丁不起作用,打破在启动服务器。
https://github.com/intridea/grape/issues/417

I have found the following issue on github but applying the given monkey patch does not work and breaks the server on startup. https://github.com/intridea/grape/issues/417

我使用的宝石以下版本,由于依赖冲突,我无法对它们进行升级:

I am using the following version of gems and am unable to upgrade them due to dependency conflicts:

grape (0.2.1.1)
rails(3.0.7)
rspec-rails (2.6.1)

任何帮助和提示,将大大AP preciated。

Any help and tips will be greatly appreciated.

推荐答案

如果我记得应该有一个报头中设置内容类型与价值应用程序/ x-WWW的形式urlen codeD

If I recall there should be a header set Content-Type with the value application/x-www-form-urlencoded

这篇关于葡萄API忽略PUT / POST PARAMS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆