Params变量没有填充JSON帖子数据....为什么?

MrW*_*ter 2 rest json ruby-on-rails params

我之前使用过这个服务,还有其他一些领域,但是现在我似乎没有让它工作,并且我不太明白为什么.

我将以下json发布到我的Rails应用程序(使用RestClient 2.4,用于测试):

{
    "camp":{
        "total": 100,
        "number": "epw1f6e"
    },
    "machine":{
        "serial_number": "1234567",
        "token": "fONxDN"
    }
}
Run Code Online (Sandbox Code Playgroud)

营地控制员:

def create
    if is_it_json?
      logger.debug params.inspect
      machine = Machine.find_by_serial_number(params[:machine][:serial_number])
...
Run Code Online (Sandbox Code Playgroud)

从记录器中,我得到的参数是:{"action"=>"create","controller"=>"camp"}

json信息在哪里?

我的日志错误:

Started POST "/camps" for 127.0.0.1 at 2012-07-15 00:08:21 +0100
Processing by CampsController#create as JSON
WARNING: Can't verify CSRF token authenticity
{"action"=>"create", "controller"=>"camps"}
Completed 500 Internal Server Error in 2ms

NoMethodError (undefined method `[]' for nil:NilClass):
  app/controllers/camps_controller.rb:24:in `create'
Run Code Online (Sandbox Code Playgroud)

我可能做错了什么?

谢谢

MrW*_*ter 6

经过大量的阅读和质疑,我发现了解决方案:

params没有被填满,因为我失去了Headers(我有了Accept,但是错过了Content-type):

Accept: application/json
Content-type: application/json
Run Code Online (Sandbox Code Playgroud)

添加标题解决了这个问题.