How do I ignore the authenticity token for specific actions in Rails?

后端 未结 2 1557
既然无缘
既然无缘 2020-12-02 06:31

When I have a specific action that I don\'t want to check the authenticity token on, how do I tell Rails to skip checking it?

2条回答
  •  没有蜡笔的小新
    2020-12-02 07:28

    In Rails 4:

    skip_before_action :verify_authenticity_token, except: [:create, :update, :destroy]
    

    And Rails 3:

    skip_before_filter :verify_authenticity_token
    

    For previous versions:

    For individual actions, you can do:

    protect_from_forgery :only => [:update, :destroy, :create]
    #or
    protect_from_forgery :except => [:update, :destroy, :create]
    

    For an entire controller, you can do:

    skip_before_action :verify_authenticity_token
    

提交回复
热议问题