14

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"

Brian Armstrong
  • 19,707
  • 17
  • 115
  • 144

3 Answers3

11

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
rnicholson
  • 4,538
  • 1
  • 22
  • 13
  • Hi Micholson, thanks for the response. I agree you'd normally want to feeeze them, but due to the nature of this bug I'd like to have it fixed across all my rails apps (and hopefully not check a ton more files into version control). I might be able to get it just from what you've written though - after reading up no the -p option the directory problem makes more sense: http://linux.die.net/man/1/patch Cheers! – Brian Armstrong May 30 '09 at 20:21
8

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.

Brian Armstrong
  • 19,707
  • 17
  • 115
  • 144
0

Here is a shell one-liner for patching a gem:

patch -d "$(gem env gemdir)"/gems/actionmailer-* -p1 < <(curl -s https://rails.lighthouseapp.com/attachments/108548/0001-Fix-implicit-multipart-mailer-views-when-RAILS_ROOT.patch)

Another example using gist gem:

patch -d "$(gem env gemdir)"/gems/gist-* -p1 < <(curl -s https://github.com/defunkt/gist/commit/5843e9827f529cba020d08ac764d70c8db8fbd71.patch)

kenorb
  • 155,785
  • 88
  • 678
  • 743