PatchPatch changes Rails’ default behavior of mapping PUT and PATCH
requests on resources to the same action.
Installation
Add this line to your application's Gemfile:
gem 'patch-patch'And then execute:
$ bundleUsage
PatchPatch hooks itself automatically into Rails’ routing engine. You don’t have to enable or configure it.
Let’s say we have a RESTful API with a single users resource.
# config/routes.rb
Foo::Application.routes.draw do
resources :users
endBefore
$ rake routes
Prefix Verb URI Pattern Controller#Action
users GET /users(.:format) users#index
POST /users(.:format) users#create
new_user GET /users/new(.:format) users#new
edit_user GET /users/:id/edit(.:format) users#edit
user GET /users/:id(.:format) users#show
PATCH /users/:id(.:format) users#update
PUT /users/:id(.:format) users#update
DELETE /users/:id(.:format) users#destroyAfter
$ rake routes
Prefix Verb URI Pattern Controller#Action
users GET /users(.:format) users#index
POST /users(.:format) users#create
new_user GET /users/new(.:format) users#new
edit_user GET /users/:id/edit(.:format) users#edit
user PATCH /users/:id(.:format) users#partial_update
GET /users/:id(.:format) users#show
PATCH /users/:id(.:format) users#update
PUT /users/:id(.:format) users#update
DELETE /users/:id(.:format) users#destroyNote: the old PATCH route is still there but it will never be matched since our #partial_update route comes first. The old PUT route will still route to #update though.
License
PatchPatch is © 2013 Mirego and may be freely distributed under the New BSD license. See the LICENSE.md file.
The patch logo is based on this lovely icon by Christina W, from The Noun Project. Used under a Creative Commons BY 3.0 license.
About Mirego
Mirego is a team of passionate people who believe that work is a place where you can innovate and have fun. We're a team of talented people who imagine and build beautiful Web and mobile applications. We come together to share ideas and change the world.
We also love open-source software and we try to give back to the community as much as we can.