嗨,我有rails 5应用程序,它在提交POST请求登录时抛出以下错误Can't verify CSRF token authenticity. ActionController::InvalidAuthenticityToken错误。这很奇怪,因为form在生产和开发环境中工作得很好。以下是请求参数
{
"method":"POST",
"path":"/users/sign_in",
"format":"html",
"controller":"Users::SessionsController",
"action":"create",
"status":422,
"error":"ActionController::InvalidAuthenticityToken: ActionController::InvalidAuthenticityToken",
"duration":11.53,
"view":0.0,
"params":{
"utf8":"✓",
"authenticity_token":"LDPxQ17rH9W/AoW1Hfeyd4in1Ms7snMuys6IyFIlB6K9JoCLanfjHg6OOcqlf/HkE9pPzEuOwVz3d29iwYaJbA==",
"user":{
"email":"",
"password":"[FILTERED]"
},
"commit":"Login"
},
"@timestamp":"2018-05-23T12:08:26.463Z",
"@version":"1",
"message":"[422] POST /users/sign_in (Users::SessionsController#create)"
}发布于 2018-05-23 22:12:51
您可以将此代码添加到控制器
skip_before_action :verify_authenticity_token当然不推荐这样做,但出于某种原因,它解决了我的问题,因为它只在我的整个应用程序的一个表单上发生,跳过这个身份验证是安全的。
https://stackoverflow.com/questions/50488230
复制相似问题