Is Rails 3 a "_method = PUT" that should still work?

I use FLEX 3 to make an XML request for Rails 3. Since FLEX 3 only offers POST and GET, I have to use the hacker “? _Method = PUT” to maintain proper RESTfulness:

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

On the server side, it appears as a POST, and I get an ActionController :: RoutingError (no route matches).

I did rake routes, and the route there, duly impressive and all. This works fine with Rails 2, so I have reason to believe that it is Rails 3 that has changed. After some searching, people seemed to indicate that they should work anyway. But this is not for me. Can anyone confirm or deny Rails 3 compatibility?

UPDATE

Well, after some more messing around, I think this is actually a Flash Player 10 issue. Flash PLayer 9 seems to work fine with the "_method =" hack, 10 doesn't. View a new post I wrote ( Flash Player 9 vs Flash Player 10 with FLEX 3 ,? _method = PUT / DELETE does not work? ).

+2
source share
3 answers

This is partly due to behavior Rack::MethodOverride. It does not check the request parameters for _method, so the call http://127.0.0.1:3000/locator/locator_users/1.xml?_method=PUT will not be properly canceled because of this.

I wrote a piece of rack middleware that replaces it in order to fix this particular problem.

, , Gemfile

gem 'rack-methodoverride-with-params'

swack Rack:: MethodOverride out config/environment.rb

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

_method=PUT , .

, ( ) , , , , :

# config/routes.rb
post '/locator/locator_users/:id', to: 'locator_users#update', constraints: {_method: 'POST'} # allow http method override

, , HTTP, , , HTTP.

EDIT: GET, , post get ( , REST JSONP).

+1

, , . Rails 3, Flex 4 Flash 10 ( , Flex 3) _method HTTPService ( application/x-www-form-url).

HTTPServiceonly supports queries GETand POST. If you are using the property set useProxyto true for the HTTPService object, you can use the HEAD, OPTIONS, TRACE, and DELETE, but only if you are also using a proxy server service. If this does not work, you can try URLLoaderor URLRequestor implement your own solution instead.

0
source

Source: https://habr.com/ru/post/1741966/


All Articles