Rails protect_from_forgery

hiveer · 2014年05月14日 · 最后由 hiveer 回复于 2014年05月15日 · 3412 次阅读

我面对的场景是这样 针对某个 controller 下的 show action 我现在确实有两个请求方式,假设是硬性的。 但是你知道 POST 会被 protect_from_forgery 给拦下来,所以我希望能 skip 掉。 如果能附上 rails 定义的 POST 请求如何穿过 protect_from_forgery,那就更好了!

google

For individual actions, you can do:

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

For an entire controller, you can do:

skip_before_filter :verify_authenticity_token

#1 楼 @saiga 似乎没能解决掉我的问题哟,针对的是同一个 action 的不同调用方式(POST,GET)。 我正努力 google 中,如果有进展会及时更新!谢谢你的回答 saiga!

#2 楼 @hiveer get 请求不会拦截的。判断 get 还是 postrequest,method == 'GET'

#4 楼 @5swords 似乎没有针对我这种问题的的解决方案,但是直接 skip show 这个方法也是可以的。

需要 登录 后方可回复, 如果你还没有账号请 注册新账号