当我不想检查真实性令牌的特定操作时,如何告诉 Rails 跳过检查它?
轨道 5.2+
您可以使用相同的skip_before_action https://api.rubyonrails.org/classes/ActionController/RequestForgeryProtection/ClassMethods.html#method-i-skip_forgery_protection下面列出的方法或新方法skip_forgery_protection
这是一个薄包装纸skip_before_action :verify_authenticity_token
skip_forgery_protection
轨道 4+:
# entire controller
skip_before_action :verify_authenticity_token
# all actions except for :create, :update, :destroy
skip_before_action :verify_authenticity_token, except: [:create, :destroy]
# only specified actions - :create, :update, :destroy
skip_before_action :verify_authenticity_token, only: [:create, :destroy]
查看所有选项@ api.rubyonrails.org https://api.rubyonrails.org/classes/ActionController/RequestForgeryProtection/ClassMethods.html#method-i-protect_from_forgery
轨道 3 及以下:
skip_before_filter :verify_authenticity_token
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)