rails 2.3.2 ActiveResource fieldnames uncamelizing

Hey all,

Just updated rails and i have a bunch of activeresource models that
connect to a bunch of tables that don't follow the rails naming
convention.. they actually have CamelCase field names, which wasn't my
idea, but i have to deal with it.. it was working fine pre-upgrade,
but now when i get an object or hash from activeresource the
fieldnames/keys are uncamelized (ie: CustomerID becomes

This change is causing me much grief and i don't want to keep
referencing the fields by their actual fieldnames.

I know that the new rails allows for you to swap the xml parser out
for another one though i haven't actually figured out how to do this.
I used to have the faster_from_xml plugin installed on my app along
with the libxml-ruby gem, but the upgrade broke the plugin so i
deleted the plugin. Is it the parser that is doing that to the field
names or is it something inside activesupport?

thanks a bunch!


I once looked into this as well, but worked around it… :slight_smile:

Anyways, the problem was introduced in Hash.from_xml iirc,
it has nothing to do with the recent changes to xml mini.


I searched my irc logs and found the chat where I mentioned the
specific commit:

I don't remember how well I tested that though. But do find out :slight_smile:


Thanks for the reply Eloy. I took a look at the link to that commit
you posted, but i'm not sure if its exactly what i'm looking for. If
i'm reading the code correctly (specifically the activesupport bits
since activerecords to_xml seems to be working as i want it to) the
code seems to look for a :camelize option passed along and then
camelizes the key if its set and dasherizes the key by default.. what
i want to do is just keep the fieldname / tag the same regardless of
what naming convention is used.

The test case would be something like this:

xml = %(<blah_blah> <JunkOne> 1 </JunkOne> <JunkTwo> 2 </JunkTwo>
<dasherized_tag> 3 </dasherized_tag> </blah_blah>

h = Hash.from_xml(xml)

assert_equal(h, {"blah_blah" => {"JunkOne" => "1", "JunkTwo" => "2",
"dasherized_tag" => "3"}})

notice that regardless of the tag name the key is the same string.
what rails is currently doing is giving me a result that looks like
{"blah_blah" => {"junk_one" => "1", "junk_two" => "2",
"dasherized_tag" => "3"}}

Forgive me if that is indeed what the commit you posted will
accomplish.. it's been a long day and i had my app almost ready to
deploy prior to this new release of rails.

Thanks a million,


sorted it out today..
line 223 from activesupport/lib/active_support/core_ext/hash/
h[k.to_s.underscore.tr("-", "_")] = unrename_keys(v)

changed to

h[k.to_s.tr("-", "_")] = unrename_keys(v)

any specific reason they decided to force the tags/attributes to
underscored keys?