轨道3是“_method = PUT”仍然应该工作? [英] Rails 3 is "_method=PUT" still supposed to work?

查看:149
本文介绍了轨道3是“_method = PUT”仍然应该工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用FLEX 3向Rails 3发出XML请求。由于FLEX 3只提供POST和GET,所以我必须使用?_method = PUThack来保持适当的RESTfulness:

  http://127.0.0.1:3000/locator/locator_users/1.xml?_method=PUT 

在服务器端,它显示为一个POST,并且我得到一个ActionController :: RoutingError(No Route Matches)。



我做了一个rake路由,路由在那里,正确命名空间和所有。
这对Rails 2来说工作得很好,所以我有理由相信它必须改变Rails 3。经过一番搜索之后,人们似乎已经表示应该仍然有效。但是,这不适合我。任何人都可以确认或拒绝Rails 3的兼容性吗?
$ b

UPDATE 一些更多的修补,我认为这实际上是一个Flash Player 10的问题。Flash PLayer 9似乎正常工作与_method =hack,10没有。看到这个新的职位,我写道( Flash Player 9与带有FLEX 3的Flash Player 10,?_method = PUT / DELETE不起作用?)。

解决方案

部分原因是由于 Rack :: MethodOverride 的行为。它不检查 _method 的查询参数,所以调用 http://127.0.0.1:3000/locator/locator_users/1.xml ?_method = PUT
不会被正确覆盖,因为这个。



我写了一个一块Rack中间件,它可以替代它来解决这个特殊问题。



您只需将
添加到 Gemfile

  gem'rack-methodoverride-with-params'

swap Rack :: MethodOverride out config / environment.rb

  config.middleware.swap机架: :MethodOverride,Rack :: MethodOverrideWithParams 


I'm using FLEX 3 to make XML request to Rails 3. Since FLEX 3 only offers POST and GET, I have to use the "?_method=PUT" hack to maintain proper RESTfulness:

http://127.0.0.1:3000/locator/locator_users/1.xml?_method=PUT

On the server side its showing up as a POST and I'm getting an ActionController::RoutingError (No Route Matches).

I did a rake routes and the route is there, properly namespaced and all. This worked fine with Rails 2, so I have reason to believe it must be Rails 3 that changed. After doing some searching, people seemed to have indicated that it should still work. But, it's not for me. Can anyone confirm or deny Rails 3 compatibility?

UPDATE

OK, after some more tinkering, I think this is actually a problem of Flash Player 10. Flash PLayer 9 seems to work fine with "_method=" hack, 10 does not. See this new post I wrote (Flash Player 9 vs Flash Player 10 with FLEX 3, ?_method=PUT/DELETE not working?).

解决方案

Partly this is due to Rack::MethodOverride's behavior. It does not check the query params for _method, so a call to http://127.0.0.1:3000/locator/locator_users/1.xml?_method=PUT will not get overridden properly due to that.

I wrote a piece of Rack middleware that replaces it to fix this particular issue.

All you have to do is add it to the Gemfile

gem 'rack-methodoverride-with-params'

swap Rack::MethodOverride out in config/environment.rb

config.middleware.swap Rack::MethodOverride, Rack::MethodOverrideWithParams

这篇关于轨道3是“_method = PUT”仍然应该工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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