# Rails 2.3.2 ActiveResource fieldnames uncamelizing

**URL:** <https://www.ruby-forum.com/t/rails-2-3-2-activeresource-fieldnames-uncamelizing/163169>\
**Category:** Rails\
**Created:** [March 17, 2009, 10:45pm UTC](https://www.ruby-forum.com/t/rails-2-3-2-activeresource-fieldnames-uncamelizing/163169 "2009-03-17T22:45:06Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![stewbawka](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a9adbd/32.png) [@stewbawka](https://www.ruby-forum.com/u/stewbawka)\
**Post date:** [March 17, 2009, 10:45pm UTC](https://www.ruby-forum.com/t/rails-2-3-2-activeresource-fieldnames-uncamelizing/163169/1 "2009-03-17T22:45:06Z")

</div>

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…

Thanks,

Stuart

---

<div class="post-metadata">

**Author:** ![stewbawka](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a9adbd/32.png) [@stewbawka](https://www.ruby-forum.com/u/stewbawka)\
**Post date:** [March 18, 2009, 4:52pm UTC](https://www.ruby-forum.com/t/rails-2-3-2-activeresource-fieldnames-uncamelizing/163169/2 "2009-03-18T16:52:41Z")

</div>

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

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

Eloy

---

<div class="post-metadata">

**Author:** ![stewbawka](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a9adbd/32.png) [@stewbawka](https://www.ruby-forum.com/u/stewbawka)\
**Post date:** [March 18, 2009, 4:55pm UTC](https://www.ruby-forum.com/t/rails-2-3-2-activeresource-fieldnames-uncamelizing/163169/3 "2009-03-18T16:55:38Z")

</div>

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

> <https://github.com/rails/rails/commit/aa5cdb0d47fb5484bfdde8244df7efeb2175bf3a>
>
> Signed-off-by: Michael Koziarski \<michael@koziarski.com\>

I don’t remember how well I tested that though. But do find out 🙂

Eloy

---

<div class="post-metadata">

**Author:** ![stewbawka](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a9adbd/32.png) [@stewbawka](https://www.ruby-forum.com/u/stewbawka)\
**Post date:** [March 19, 2009, 12:43am UTC](https://www.ruby-forum.com/t/rails-2-3-2-activeresource-fieldnames-uncamelizing/163169/4 "2009-03-19T00:43:21Z")

</div>

sorted it out today…  
line 223 from activesupport/lib/active\_support/core\_ext/hash/  
conversions.rb  
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?

Stuart

---

<div class="post-metadata">

**Author:** ![stewbawka](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a9adbd/32.png) [@stewbawka](https://www.ruby-forum.com/u/stewbawka)\
**Post date:** [March 18, 2009, 8:03pm UTC](https://www.ruby-forum.com/t/rails-2-3-2-activeresource-fieldnames-uncamelizing/163169/5 "2009-03-18T20:03:41Z")

</div>

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  
this:  
{“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,

Stuart

On Mar 17, 7:53 pm, Eloy D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
