ActionController :: InvalidAuthenticityToken(ActionController :: InvalidAuthenticityToken):Rails 5

时间:2018-05-23 12:18:35

标签: ruby-on-rails ruby ruby-on-rails-5

嗨我有rails 5应用程序正在抛出以下错误 在登台环境中提交登录POST请求时出现Can't verify CSRF token authenticity. ActionController::InvalidAuthenticityToken错误。这很奇怪,因为表单在生产和开发环境中运行良好。这是请求参数

{  
   "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)"
}

1 个答案:

答案 0 :(得分:0)

您可以将其添加到控制器

skip_before_action :verify_authenticity_token

当然不建议这样做,但由于某种原因它解决了我的问题,因为它只在我的整个应用程序上发生在一个表单上,并且可以安全地跳过此身份验证。