Forum: Ruby on Rails rails 2.3.2 ActiveResource fieldnames uncamelizing

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
8889b05b9f25f84e2e6f8e66b5441155?d=identicon&s=25 stewbawka (Guest)
on 2009-03-17 22:45
(Received via mailing list)
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
424a9ce662b059c35063b405e160461d?d=identicon&s=25 Eloy Duran (el-oy)
on 2009-03-18 16:52
(Received via mailing list)
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
424a9ce662b059c35063b405e160461d?d=identicon&s=25 Eloy Duran (el-oy)
on 2009-03-18 16:55
(Received via mailing list)
I searched my irc logs and found the chat where I mentioned the
specific commit:
http://github.com/rails/rails/commit/aa5cdb0d47fb5...

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

Eloy
8889b05b9f25f84e2e6f8e66b5441155?d=identicon&s=25 stewbawka (Guest)
on 2009-03-18 20:03
(Received via mailing list)
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
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 Duran <eloy.de.en...@gmail.com> wrote:
8889b05b9f25f84e2e6f8e66b5441155?d=identicon&s=25 stewbawka (Guest)
on 2009-03-19 00:43
(Received via mailing list)
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
This topic is locked and can not be replied to.