Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you apply a patch to ruby on rails?

I'd like to apply the action_mailer patch mentioned in this thread but I have never applied a patch before and I'm not sure how these work: https://rails.lighthouseapp.com/projects/8994/tickets/2263

My action mailer gem is here: /opt/ruby-enterprise-1.8.6-20090421/lib/ruby/gems/1.8/gems/actionmailer-2.3.2

I assume I need to go to that directory and run the patch command...something like this?

cd /opt/ruby-enterprise-1.8.6-20090421/lib/ruby/gems/1.8/gems/
wget https://rails.lighthouseapp.com/attachments/108548/0001-Fix-implicit-multipart-mailer-views-when-RAILS_ROOT.patch
patch < 0001-Fix-implicit-multipart-mailer-views-when-RAILS_ROOT.patch

One thing I'm not really clear on also is that the patch file refers to the "actionmailer" directory but mine is called "actionmailer-2.3.2"

like image 204
Brian Armstrong Avatar asked May 30 '09 17:05

Brian Armstrong


2 Answers

You typically don't want to patch the gem source itself. You probably will want to freeze the gems into ${RAILS_ROOT}/vendor/rails, and then apply the patch locally.

From your ${RAILS_ROOT} dir, dump all of your rails gems into vendor/rails

rake rails:freeze:gems

Apply the patch

  cd vendor/rails/ 
  patch -p1 < 0001-Fix-implicit-multipart-mailer-views-when-RAILS_ROOT.patch
like image 132
rnicholson Avatar answered Sep 23 '22 17:09

rnicholson


Micholson's answer above works. But to patch the actual gem for all rails apps (see my comment on his answer) this worked:

cd /opt/ruby-enterprise-1.8.6-20090421/lib/ruby/gems/1.8/gems/actionmailer-2.3.2
wget sudo wget https://rails.lighthouseapp.com/attachments/108548/0001-Fix-implicit-multipart-mailer-views-when-RAILS_ROOT.patch
sudo patch -p2 < 0001-Fix-implicit-multipart-mailer-views-when-RAILS_ROOT.patch
sudo rm 0001-Fix-implicit-multipart-mailer-views-when-RAILS_ROOT.patch

I found out you can also reverse a patch with -R if anything goes wrong. I'm surprised this process wasn't better documented somewhere. Hopefully this will turn up in Google searches for people new to patching like me.

like image 29
Brian Armstrong Avatar answered Sep 23 '22 17:09

Brian Armstrong