Updating Resources With Patch

With the introduction of Rails 4, comes official support for a long neglected HTTP protocol, Patch. This change was first proposed over two years ago in Rails issue #348.

In Rails 3.2 and earlier, the Put command was used whenever an existing resource was updated.

Now with the introduction of Patch, the Rails controller will prefer it’s use when an existing resource is being partially updated. Leaving the Put command for instances in which the record is being updated in it’s entirety.

With this change, the vast majority of record updates will now occur using Patch.

Update Controller - Rails 4
1
2
PATCH  /feature/:id(.:format)   features#update
PUT    /feature/:id(.:format)   features#update

Additional reading on Patch

PATCH Method for HTTP – IETF proposal for the use of Patch

Patch is the new primary HTTP method for updates – Edge Rails blog post on the Patch method.

Restful Web Services – Defacto O’Reilly book on using HTTP routes & codes to create restful applications.