RVM, Ruby 1.9.2, and Rails 2.3.8
File this one under the “that shouldn’t have worked, but it did” category. I decided that it was high time to start using Ruby 1.9, but didn’t want to mess around trying to get it to live happily side-by-side with my stock Snow Leopard installation of Ruby 1.8.whatever. I know it’s supposed to be relatively painless, but I just didn’t want to go there. So, I decided to try out RVM. Installing it was a breeze, and getting the newest version of Ruby installed was even easier. RVM is a seriously well-documented piece of software, I gotta say.
So, after installing, my natural next step was to try and see if one of my current Rails 2.3.8 projects played nicely with 1.9. Installing the required gems into RVM’s sandbox was pretty painless (except for ruby-debug, but whatever), but when I went to run script/console
, I got the following unhelpful error message:
/Users/steven/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-2.3.8/lib/action_controller/cgi_ext/stdinput.rb:14:in `included': undefined method `alias_method_chain' for CGI:Class (NoMethodError) ...
Googling was surprisingly unhelpful- there’s a 7-month-old Lighthouse ticket for the Rails Guides project that reported exactly the same error with Rails 2.3.5, but there aren’t any comments on the ticket. Other than that, I wasn’t finding much. In desperation, I started looking for various other alias_method_chain
errors, and eventually stumbled on this guy, who reported a similar-looking error that occurred in a completely different file and with a completely different version of Rails. Something about it tickled a neuron- his problem eventually turned out to be related to his version of Ruby not getting linked against libiconv
when it was compiled by RVM. I checked, and discovered that my RVM 1.9.2 installation didn’t seem to know about iconv
, either (i.e., running require 'iconv'
threw an error). This was probably due to the fact that my version of libiconv
was installed using MacPorts, and RVM can’t seem to find MacPorts libraries unless I explicitly tell it to.
Even though my problem seemingly had nothing to do with iconv
, I was desperate enough to give recompiling a shot, and I figured that not being able to find iconv
would certainly end up causing some sort of weird problem down the road. I followed the instructions found here, and, lo and behold, my Rails 2.3.8 started working beautifully.
I don’t know why this worked. The error I was getting seemed to have nothing to do with iconv
, or, actually, any kind of character encoding stuff at all- there was nothing in the stack trace to suggest that anybody was trying to require iconv
, or anything like that. Recompiling Ruby again shouldn’t have fixed it, but it did. This is always a disconcerting phenomenon, but you know what? It’s working now, and I really don’t care to go digging any further. Software, laws, and sausages- three things into which I don’t care to dig too deeply.
I’m putting this up online in the hopes that Google will find it and save somebody else some headache down the road. Pay it forward, right? If anybody reading this post has any ideas as to what was going on, leave a comment or drop me an email.