Ruby parsing XML: no implicit conversion of String into Integer

no implicit conversion of string into integer ruby hash
no implicit conversion of string into integer - chef
no implicit conversion of symbol into integer params
no implicit conversion of array into string
no implicit conversion of runtimeerror into string
no implicit conversion of nil into string
ruby convert string to integer
no implicit conversion of integer into string logstash

I'm working on a Sinatra application that pulls in a list of dates through an XML file and then creates an hash of all the dates.

I'm running into a strange issue that's happening when I'm pulling the id and assigning it to a variable.

The error I'm getting is: no implicit conversion of String into Integer and it's being thrown on the event_date_id = event_date["date_id"] line. I have almost identical method in my code and it's working just fine. When I puts event_date['date_id'] it gives me the correct numerical date_id.

Just in case it helps, the class of the event_date['date_id'] is REXMLUtiliyNodeString, same as the id field in the other method. If I try to event_date['date_id'].to_i it gives breaks at that point.

def get_dates(event_id)

url = "some_url_to_some_xml"
puts '==================='
puts "Pulling in #{url}"
puts '==================='
date_xml = Crack::XML.parse(open(url))

dates = {}

date_xml['document']['date'].each do | event_date |

  event_date_id = event_date['date_id']

  single_date = {
    'date_id' => event_date_id,
    'date_start' => event_date['datestart'],
    'date_end' => event_date['dateend'],
    'date_live' => event_date['live'],
    'time_start' => event_date['timestart'],
    'time_end' => event_date['timestart'],
    'date_available' => event_date['date_available']
  }

  dates.merge!( event_date_id => single_date )

end

return dates

end

Here is the xml format:

<document>
    <date>
        <date_id>881908</date_id>
        <live>y</live>
        <datestart>2017-08-14</datestart>
        <dateend>2017-08-15</dateend>
        <timestart>13:00</timestart>
        <timeend>0:00</timeend>
        <date_available>10000</date_available>
    </date>
<document>

I have a feeling this is something really simple but I'm wracking my brains trying to figure it out. If anyone could shed some light on this, I'd definitely appreciate it.

Edit 1: When I run the code in irb, it does indeed work without error. Somewhere, somehow it seems Sinatra, Rack or Shotgun are getting in the way.

I have found the cause of my issue. It only occurs when I'm parsing an xml file with one entry for date/event whatever.

This question explains the exact issue I was having and the answer includes a work around that worked for me.

if(!date_xml['document']['date'].is_a?(Array))
  date_xml['document']['date'] = [ date_xml['document']['date'] ]
end

I am getting a TypeError saying "no implicit conversion of String into , Why is an integer required here? In the contact_list array, it seems the phone number is listed as a string, so I am confused as to why I need to  Looking for related GitHub issues on fastlane/fastlane ️ [PEM] fastlane pem fails on multiple app_identifiers no implicit conversion of Array into String #13559 [open] 13 💬 a week ago ️ latest_testflight_build_number + 1 -> [!] no implicit conversion of Fixnum into String #12097 [closed] 11 💬 23 May 2018

This message occurs when you try to use a string index to look up a value in an array.

2.0.0p353 :001 > results = [""]
 => [""] 
2.0.0p353 :002 > results["x"]
TypeError: no implicit conversion of String into Integer
    from (irb):2:in `[]'
    from (irb):2
    from /home/jeff/.rvm/rubies/ruby-2.0.0-p353/bin/irb:12:in `<main>'

Since arrays can only be accessed by integer indexes, Ruby attempts to transform your key name into an integer, and fails because it doesn't know what number should be used to represent arbitrary string data. Hence the message "no implicit conversion of String into Integer".

If you're experiencing this, the answer is to fix your code so that it doesn't try to access an array like a hash. If you're importing from XML or JSON data on the assumption that the key desired is always there and will always be imported, but you're still getting this, your assumption is wrong; the data is not formatted as expected. Either fix the data or fix the code to handle the differing format.

no implicit conversion of String into Integer Ruby on Rails, I'm doing a dropdown field that gets it's values from another controller, I defined it like this: def dropdown @tarefa_list = Tarefa.all.map { |c| [c. The "+" is crashing in TypeError: [!] no implicit conversion of Fixnum into String Fastfile:27:in +' Fastfile:27:in block (2 levels) in parsing_binding' New Issue Checklist Updated fastlane to the latest version I read the Contribution G

I randomly stumbled upon what may be a better answer to this question, although I am very inexperienced so I think it needs to be verified.

I had an identical issue and saw that much of the trouble seems to be because I was returning a somewhat confusing array of one object.

Once I added ".first" to my query, I was able to retrieve my intended attribute.

  response = File.open('ncaa_bb_schedule.xml')
  doc = Nokogiri::XML(response)
  doc.remove_namespaces!
  doc.xpath('//game').each do |game|
    h = game.xpath('home').first
    p h['id']
  end

But my original query, shown here

  response = File.open('ncaa_bb_schedule.xml')
  doc = Nokogiri::XML(response)
  doc.remove_namespaces!
  doc.xpath('//game').each do |game|
    h = game.xpath('home')
    p h['id']
    end
  end

was giving me the same error: "TypeError: no implicit conversion of String into Integer." Hope that helps somebody as it is much shorter than the aforementioned workaround.

no implicit conversion of String into Integer · Issue #188 · jwt/ruby-jwt, I had some problems handling this library concerning insert an array into JWT.​encode, suposing I have a JSON in array format. Testing on  Logstash XML parsing issues - trying to send to Graylog, part 2 ruby - Ruby exception occurred: no implicit conversion of String into Integer [ERROR] 2019-07-31

ruby-2.0, rails-4 no implicit conversion of Symbol into Integer, ruby - No implicit conversion of symbol to integer for Sinatra file up ruby file-​upload sinatra - Ruby parsing XML: no implicit conversion of String into Inte. Hey you all, I published a blog post telling some great things that happened during a year of attending to ruby meetups in my city. I don't know, but I feel like ruby meetups are slowly getting fewer and fewer people, not because "ruby is dying ™" (which i don't believe it's true) but because I don't see people I know that code in ruby at work in these meetups or because they are not

JUnit XML Merge Request Widget - Test Results failed to load, JUnit XML Merge Request Widget - Test Results failed to load parsing failed: no implicit conversion of String into Integer"}". junit.xml generated by PHPUnit 6.5​.9. "/home/git/gitlab/vendor/bundle/ruby/2.4.0/gems/activesupport-4.2.10/lib/  Now you’re going to learn how to use the Ruby CSV library to read & write CSV files. Ruby CSV Parsing. Ruby comes with a built-in CSV library. You can read a file directly: require 'csv' CSV.read("favorite_foods.csv") Or you can parse a string with CSV data: require 'csv' CSV.parse("1,chocolate 2,bacon 3,apple") The result?

TypeError: no implicit conversion of String into Integer, TypeError: no implicit conversion of String into Integer. June 13 data = JSON.​parse(response.body) data["result"].each do |c| existing_city  In Java, we can use Integer.parseInt() or Integer.valueOf() to convert String to int. Integer.parseInt() – return primitive int. Integer.valueOf() – return an Integer object. For position or negative number in String, the convert is the same.

Comments
  • I know this is less than helpful, but it works fine on my machine (Mac OS 10.8, ruby 2.0.0)
  • Thanks for taking a look. I guess that makes it something wrong with my environment!