0.0
No commit activity in last 3 years
No release in over 3 years
PatchPatch changes Rails’ default behavior of mapping PUT and PATCH requests on resources to the same action.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0

Runtime

>= 4.0.0
 Project Readme

PatchPatch
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:

$ bundle

Usage

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
end

Before

$ 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#destroy

After

$ 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#destroy

Note: 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.