如何忽略 Rails 中特定操作的真实性令牌? [英] How do I ignore the authenticity token for specific actions in Rails?

查看:54
本文介绍了如何忽略 Rails 中特定操作的真实性令牌?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我有一个不想检查真实性令牌的特定操作时,我如何告诉 Rails 跳过检查它?

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?

推荐答案

Rails 5.2+

您可以使用相同的skip_before_action 下面列出的方法或新方法 skip_forgery_protection,它是 skip_before_action :verify_authenticity_token

You can use the same skip_before_action method listed below or a new method skip_forgery_protection which is a thin wrapper for skip_before_action :verify_authenticity_token

skip_forgery_protection

Rails 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

Rails 3 及以下:

Rails 3 and below:

skip_before_filter :verify_authenticity_token

这篇关于如何忽略 Rails 中特定操作的真实性令牌?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆