This project is archived and is in readonly mode.
ActiveResource errors.from_xml Can't handle symboled attribute keys because of humanize call
Reported by Matthew Moore | November 25th, 2008 @ 08:09 PM | in 3.x
If you look at:
# Grabs errors from the XML response.
def from_xml(xml)
clear
humanized_attributes = @base.attributes.keys.inject({}) { |h, attr_name| h.update(attr_name.humanize => attr_name) }
messages = Hash.from_xml(xml)['errors']['error'] rescue []
messages.each do |message|
attr_message = humanized_attributes.keys.detect do |attr_name|
if message[0, attr_name.size + 1] == "#{attr_name} "
add humanized_attributes[attr_name], message[(attr_name.size + 1)..-1]
end
end
add_to_base message if attr_message.nil?
end
end
end
You'll notice humanized_attributes =
@base.attributes.keys.inject({}) { |h, attr_name|
h.update(attr_name.humanize => attr_name) }
... and in
particular, attr_name.humanize
. If the attribute key
is a symbol instead of a string (say you're working directly from
the command line), you'll get an exception from that line:
/activeresource-2.2.2/lib/active_resource/validations.rb:205:in `from_xml': undefined method `humanize' for :[whatever attr_name is]:Symbol (NoMethodError)
It seems like this would be a simple fix (just
attr_name.to_s.humanize
). Is anyone else having this
problem?
Comments and changes to this ticket
-
Michael Koziarski December 1st, 2008 @ 08:01 PM
This sounds like a good fix to me, attach a patch with tests and we're good to go.
-
Matthew Moore December 1st, 2008 @ 08:13 PM
Actually I've been looking into this more, and it might be better instead to
stringify_keys!
in theattributes=
method like ActiveRecord does. Still thinking about it...Do you have any thoughts on what you'd prefer?
-
Michael Koziarski December 1st, 2008 @ 08:15 PM
consistency with AR is probably worth doing, plus it makes it a little less ad-hoc compared to sticking .to_s somewhere. It'll also stop any other issues from popping up later.
-
Pratik March 13th, 2009 @ 11:14 AM
- Title changed from ActiveResource 2.2.2 errors.from_xml Can't handle symboled attribute keys because of humanize call to ActiveResource errors.from_xml Can't handle symboled attribute keys because of humanize call
-
Yuri March 13th, 2009 @ 03:40 PM
I have just posted a bug report where the cause of the problem is this very method, though the problem is different - #2229
-
CancelProfileIsBroken August 5th, 2009 @ 03:34 PM
- Tag changed from activeresource, bug to activeresource, bug, bugmash
-
Dan Pickett August 8th, 2009 @ 09:30 PM
patch attached validated +1
I took a swing at a patch for this to stringify the keys. pretty simple.
-
Steve St. Martin August 8th, 2009 @ 10:12 PM
+1 patch applies cleanly to both 2-3-stable and master, appears to address issue and test is sufficient
-
Rizwan Reza August 8th, 2009 @ 10:17 PM
verified
+1 This patch applies to both: 2-3-stable and master cleanly.
-
Nick Quaranto August 8th, 2009 @ 10:17 PM
+1, applies cleanly and passes on both 2-3-stable and master.
-
Dan Croak August 8th, 2009 @ 10:18 PM
+1 verified in 2-3-stable.
Patch applies cleanly. activeresource rake test runs green.
-
Dan Croak August 10th, 2009 @ 02:41 AM
Pratik mentioned in IRC that he'd like to see a test for from_xml added to this patch before it is committed. I started to look into it but am on another computer. If someone gets to it first, have at it!
-
Blue Box Stephen September 27th, 2009 @ 01:51 AM
+1, patch applies cleanly and passes.
However, in 2.3-stable it looks like from_xml has been changed significantly in 2.3-stable (original code above is from 2.2.2). For example, humanize is no longer called. As such, are you sure we still need this particular test for from_xml? (See lib/active_resource/validations.rb starting line 224 in 2.3-stable).
-
sr.iniv.t September 27th, 2009 @ 07:34 PM
+1 verified.
The patch applies cleanly on 2-3-stable and tests pass. However, a different patch is needed for master because the activeresource test directory structure has changed in master.
-
Rizwan Reza February 12th, 2010 @ 12:46 PM
- Tag changed from activeresource, bug, bugmash to activeresource, bug
-
Santiago Pastorino February 2nd, 2011 @ 05:04 PM
- State changed from new to open
- Importance changed from to
This issue has been automatically marked as stale because it has not been commented on for at least three months.
The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.
Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.
-
Santiago Pastorino February 2nd, 2011 @ 05:04 PM
- State changed from open to stale
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>