0

I'm using this instance variable:

@response = HTTParty.get("http://www.bart.gov/dev/eta/bart_eta.xml")

I'm trying to parse the xml using rails 3.2:

<% @response.each do |r| %>
  <% r.each do |root| %>
    <%= root.class %>
  <% end %>
<% end %>

The output is

String Hash

I get "String Hash" for "root.class". I don't understand how it can be "String Hash," I would like to implement another "each" method to go deeper in the xml layers.
What does "String Hash" mean?

1 Answer 1

1

Your @response object is of the type HTTParty::Response.

It looks like it's wrapping an array with two values in it: the first value is a String, "root", and the second value is a Hash.

Since you have no line breaks in your ERB code, as you iterate through the array it is printing out String and Hash on the same line.

Try using root.inspect to dig deeper into what values you're actually iterating through.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.