在Rails 3中关闭CSRF令牌 [英] Turn off CSRF token in rails 3
本文介绍了在Rails 3中关闭CSRF令牌的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个Rails应用程序,为iPhone应用程序提供一些API。
我希望能够简单地发布在资源上,而不必考虑获取正确的CSRF令牌。
我尝试了一些我在stackoverflow中看到的方法,但似乎它们不再适用于Rails3。
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屋!
查看全文