Patching Rails and gems locally
How many times did you have to wait ages until a patch that you’ve submitted gets merged into the Rails or a gem? Sometimes you can’t wait, it’s confusing to keep external libraries in your repository. Fortunatelly – Rails provides a simple way to unpack dependencies into vendor directory, where it’s possible to make local changes. Instead of tracking whole vendor, you can have small .patch files in a separate directory and apply them to frozen vendor stuff. You won’t need to remember which gems are locally modified, repository stays small, patches can be easily applied on your remote production server by invoking rake tasks (you can use Capistrano as well). All you need is a simple Rake task:
Freeze your Rails and/or gems using rake rails:freeze:gems and rake gems:unpack. You have to store your patches as shown below. Notice that gem’s patches directories must include the version number (just like in vendor/gems).

To apply the patches run rake patch:gems or rake patch:rails task (rake patch:all). Don’t forget to add vendor/rails and vendor/gems to your .gitignore.