在 rails 3 中关闭 CSRF 令牌 [英] Turn off CSRF token in rails 3

查看:21
本文介绍了在 rails 3 中关闭 CSRF 令牌的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 Rails 应用程序,可以为 iPhone 应用程序提供一些 API.我希望能够简单地在资源上发布而不关心获得正确的 CSRF 令牌.我尝试了一些我在 stackoverflow 中看到的方法,但它们似乎不再适用于 rails 3.

I have a rails app that serves some APIs to an iPhone application. I want to be able to simply post on a resource without minding on get the correct CSRF token. I tried some methods that I see here in stackoverflow but it seems they no longer work on rails 3.

谢谢你帮助我.

推荐答案

在要禁用 CSRF 的控制器中进行检查:

In the controller where you want to disable CSRF the check:

skip_before_action :verify_authenticity_token

或者禁用除少数方法之外的所有功能:

Or to disable it for everything except a few methods:

skip_before_action :verify_authenticity_token, :except => [:update, :create]

或仅禁用指定的方法:

skip_before_action :verify_authenticity_token, :only => [:custom_auth, :update]

更多信息:RoR 请求伪造保护

这篇关于在 rails 3 中关闭 CSRF 令牌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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