Rails 2.3.2 ActiveResource fieldnames uncamelizing

I’m having some major issues with the new veresion of rails…

I have some activeresource models that connect to tables that don’t
follow the rails naming conventions… when i try to access an object
or hash via active resource it uncamelizes all the fieldnames / hash
keys (ie: CustomerID becomes customer_id)… using camelcase wasn’t my
idea, but i have to deal with it… it was working fine previously
under the old version.

i’m not sure if thsi is happening because of a new xml parser or
because of some new code in activesupport. i know there’s a way to
swap in a different xml parser with the new version, but i’m not
really sure how.

also, previously i had the faster_from_xml plugin installed along with
libxml-ruby gem… that broke on upgrading so i removed it and that’s
where i am now…



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:


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?


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> 1 2
<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,


On Mar 17, 7:53 pm, Eloy D. [email protected] wrote:

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs