这是我的REST路线:
app.put '/users/:id' do
content_type "application/json"
params = JSON.parse(request.body.read)
reqUserID = params[:id]
puts params[:id]
puts reqUserID
我用来检查的浏览器链接是
localhost:3000/users/71?access_token=elwu54j7ef0dxns2gwt072pfwpuxney
并且有效载荷是:
{
"id" : 71,
"first": "TU4",
"last": "TU4",
"email": "TU@cs.com",
"username": "TU358kkll",
"bio": "User, student",
"password":"Test12#"
}
我的疑惑: 1.我是否需要在JSON有效负载中使用id字段? 2.使用上面的代码,我无法显示params [:id]。我哪里错了?
谢谢!