Rails 3 is “_method=PUT” still supposed to work?

前端 未结 3 1805
耶瑟儿~
耶瑟儿~ 2020-12-12 01:32

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:

<         


        
3条回答
  •  星月不相逢
    2020-12-12 01:37

    If you can add _method=PUT in your request body, then no need to swap out the rack middleware.

    If you cannot do that, then I've come across another (lower-impact) solution, which is to simply define a custom route that accomplishes what you're looking for, for example:

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

    Granted, you would have to add this route for every resource you need HTTP method override on, but that might be a good thing if you want to limit your exposure to potential weirdness since this breaks HTTP semantics.

    EDIT: You can do the same thing with GET requests if you need to, just swap out post for get (this can be useful if you need to support REST over JSONP).

提交回复
热议问题