Page.Select Rails RJS Problem with Ruby 1.8.7
Yeah I know Ruby 1.9.1 is out now so posting something that is specific to Ruby 1.8.7 is pretty lame, but I have to.
I recently ran into (yet another) problem with a Rails site I have running with Dreamhost. It is on one of their 64-bit Debian 4 machines, so maybe it's specific to that environment, or maybe it's an issue across all Ruby 1.8.7 installations. I can't really confirm it because I'm running 1.8.6 on my home computer and my other dreamhost server is running 1.8.5.
Anyway, anything using the RJS Select method will raise an exception like this:
undefined method `[]' for #<Enumerable::Enumerator:0x........>
Initially, to get around this I just broke out my RJS into straight up JavaScript. It was clunky, but it worked. Then an excellent Dreamhost support person got back to me about the issue and pointed me to this documentation page on the Radiant CMS site, which included this little snippet that could be used to monkey-patch the issue:
unless '1.9'.respond_to?(:force_encoding)
String.class_eval do
begin
remove_method :chars
rescue NameError
# OK
end
end
end
Works like a champ.
Note: This issue just started happening about a month ago, which means Dreamhost just upgraded this server to Ruby 1.8.7 for some reason. I hope they don't do all their servers, they'll undoubtedly cause headaches when they do since this error is so obscure.
11:06 PM | 0 Comments