without-brains.net

A software developer's blog

Issue while upgrading Rails from 2.1.2 to 2.3.4

At work we recently upgraded from Rails 2.1.2 to Rais 2.3.4. Lots of good improvements in 2.3.4, my compliments to everyone who made the new release possible!

The upgrade was relatively problem free, the only real issue that we ran into was that somewhere in between 2.1.2 and 2.3.4 the *_tag helpers (text_field_tag and such) have started behaving slightly different in relation to element ids. These helper methods now call the undocumented sanitize_to_id method, which cleans up the element ids by getting rid of characters such as [ and ] and putting in underscores instead. While this is a good change (the form_for helpers were already converting the field names to such element ids, so this change makes the helpers more consistent), it was unexpected (I have not seen any documentation referencing it, not in the 2.2 or 2.3 release notes). This changed a lot of ids in web forms that we were using, and it broke a fair bit of custom Javascript which we had to repair.

So, if you’re upgrading Rails from 2.1.2 or older to 2.3.4 ensure that you check your views for custom Javascript to ensure that any fields generated by the *_tag helper methods that are being referenced with Javascript are referenced properly.

Happy coding!