Is it possible to disable the standard PUT route in Rails 4?

前端 未结 4 1284
不思量自难忘°
不思量自难忘° 2021-02-20 06:03

Rails 4 has introduced PATCH requests to be the default request method when doing the (common) partial updates on objects. This is conformal to HTTP standards and a

4条回答
  •  醉酒成梦
    2021-02-20 06:55

    To answer my own question: no, it is currently not possible to disable the default generation of the PUT/PATCH combination in rails 4, which can be clearly seen when looking at the source of ActionDispatch::Routing at https://github.com/rails/rails/blob/master/actionpack/lib/action_dispatch/routing/mapper.rb and especially those lines:

          def set_member_mappings_for_resource
            member do
              get :edit if parent_resource.actions.include?(:edit)
              get :show if parent_resource.actions.include?(:show)
              if parent_resource.actions.include?(:update)
                patch :update
                put :update
              end
              delete :destroy if parent_resource.actions.include?(:destroy)
            end
          end
    

    Obviously, there is (currently) no conditional for excluding the PUT route. I will prepare an issue or pull request for this and come back later with the result of that.

    Until then, the best workaround would be what Jorge de los Santos has suggested, although this would pretty much pollute config/routes.rb.

提交回复
热议问题