我以前有过这个服务,还有一些其他的领域,但现在我似乎没有得到它的工作,并没有完全理解为什么。Params变量没有被JSON发布数据填充....为什么?
我张贴以下JSON我的Rails应用程序(与RESTClient实现2.4,用于测试):
{
"camp":{
"total": 100,
"number": "epw1f6e"
},
"machine":{
"serial_number": "1234567",
"token": "fONxDN"
}
}
营控制器:
def create
if is_it_json?
logger.debug params.inspect
machine = Machine.find_by_serial_number(params[:machine][:serial_number])
...
从记录器,我得到的PARAMS是:{“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'
什么可能我是做错了什么?
谢谢
嗨,它只是删除了CSRF警告,但我仍然得到未定义的方法[]消息...为什么我的params变量充满了“动作”和“控制器”属性而不是“阵营”和“机器”来自我的json请求? – MrWater 2012-07-15 11:29:59