Rails 3 是“_method=PUT"还应该工作吗? [英] Rails 3 is "_method=PUT" still supposed to work?

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

问题描述

我使用 FLEX 3 向 Rails 3 发出 XML 请求.由于 FLEX 3 只提供 POST 和 GET,我必须使用?_method=PUT"技巧来保持适当的 REST 性:

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

在服务器端,它显示为 POST,我收到一个 ActionController::RoutingError(无路由匹配).

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

我做了一个 rake 路由,路由就在那里,有正确的命名空间等等.这在 Rails 2 中运行良好,所以我有理由相信一定是 Rails 3 发生了变化.经过一番搜索,人们似乎表示它应该仍然有效.但是,这不适合我.任何人都可以确认或否认 Rails 3 兼容性吗?

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?

更新

好的,经过一些修补之后,我认为这实际上是 Flash Player 10 的问题.Flash Player 9 似乎可以与_method="hack 一起工作,而 10 则不行.请参阅我写的这篇新帖子(Flash Player 9 vs Flash Player 10 with FLEX 3,?_method=PUT/DELETE 不工作?).

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?).

推荐答案

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

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.

我写了一个 Rack 中间件 来替换它来解决这个特殊的问题问题.

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

你所要做的就是将它添加到 Gemfile

All you have to do is add it to the Gemfile

gem 'rack-methodoverride-with-params'

config/environment.rb

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

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

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