Override the protect_from_forgery strategy in a controller

前端 未结 3 837
自闭症患者
自闭症患者 2021-02-06 13:21

I want to build a rails app with two different protect_from_forgery strategies: one for the web application, and one for the API.

In my application controller I have thi

3条回答
  •  渐次进展
    2021-02-06 14:03

    Late to the party, but something like this can be done:

    class YourCustomStrategy
      def initialize(controller)
      end
    
      def handle_request
      end
    end
    

    And in your ApplicationController or where you want:

    class ApplicationController < ActionController::Base
     protect_from_forgery with: YourCustomStrategy
    end
    

提交回复
热议问题