我在 Rails 3 中遇到了同样的问题,不推荐使用 controller.process。下面是我尝试使用 Rack::MethodOverride 代替 controller.process (在 Rails 2 中为我工作)的失败尝试。下面来自 ro.call 的错误是:
User sessionsController#create thread 0xb592b994 中的 ThreadError 试图加入自身
演示
params = {'action' => 'create', 'controller' => 'user_sessions',
"commit"=>"Submit", "user_session"=>{"username"=>"demo", "password"=>"demo"}}
request.env['REQUEST_METHOD'] = 'POST'
# Throw out existing params and merge the stored ones
request.parameters.reject! { true }
request.parameters.merge!(params)
request.path_parameters.reject! { true }
request.path_parameters.merge!('action' => 'create', 'controller' => 'user_sessions')
request.POST["HTTP_X_HTTP_METHOD_OVERRIDE"] = 'POST'
ro = Rack::MethodOverride.new Rails.application
ro.call request.env
if response.redirected_to
@performed_redirect = true
else
@performed_render = true
end
结尾
可能有人知道如何正确使用 Rack::MethodOverride 发送发布请求吗?