无法验证CSRF令牌的无效性

时间:2017-01-22 19:53:00

标签: ruby-on-rails ruby csrf mollie

我正在尝试安装Mollie API,但我没有让webhook工作。我在Ruby on Rails 4上工作。它一直在说无法验证CSRF令牌的无效性。我尝试了stackoverflow的几个答案,但它们不起作用。例如。

  • skip_before_filter:verify_authenticity_token
  • protect_from_forgery除了:[:notify]
  • protect_from_forgery with :: null_session,if: - > {request.format.json?}

我的通知控制器如下:

lasagne.layers.set_all_param_values(nolearnnet2.get_all_layers()[-1], weights)

如果有人有提示或暗示,我们将非常感谢! 谢谢!

1 个答案:

答案 0 :(得分:3)

您需要在控制器的最顶部拨打protect_from_forgery,或者您可以移除protect_from_forgery中的ApplicationController来电。

示例:

class ReservationsController < ApplicationController
    before_action :authenticate_user!, except: [:notify]

    skip_before_filter :verify_authenticity_token

    protect_from_forgery except: [:notify, :your_trips]

    # actions go below here

请注意,您可以将多个操作传递给:except参数

旁注:如果您正在使用仅限JSON API的应用,我建议您查看Rails API: https://github.com/rails-api/rails-api

相关问题