为什么Rails重定向我的POST而不是GET?
我正在尝试将数据发布到某个controller#action
对,但我的应用程序重定向我的POST(但不是GET),我无法弄清楚原因。
我用一种方法构建了一个裸骨控制器:
class NavigationsController 'in foo' end end
我的路由文件只有一个规则:
map.connect ':controller/:action/:id'
这是我获取和发布时的结果:
$ curl http://localhost:3000/navigations/foo/1 in foo $ curl -d 'a=b' http://localhost:3000/navigations/foo/1 You are being redirected.
规格:rails 2.3.8,ruby 1.8.7
关闭protect_from_forgery
。
对于所有控制器
在ApplicationController中注释掉(或删除) protect_from_forgery
。
class ApplicationController < ActionController::Base #protect_from_forgery # See ActionController::RequestForgeryProtection for details # ... end
对于一个或多个控制器
将skip_before_filter :verify_authenticity_token
添加到控制器声明中。
class NavsController < ApplicationController skip_before_filter :verify_authenticity_token # ... end
对于一个或多个动作
在上述skip_before_filter
或protect_from_forgery
命令中添加:except
选项。
class MyController < ApplicationController protect_from_forgery :except => :index end class MyOtherController < ApplicationController skip_before_filter :verify_authenticity_token, :except => [:create] end