Why Do I Get "No Implicit Conversion of String into Integer (Typeerror)"

No implicit conversion of String into Integer (TypeError)?

Write as

@systemid = @getsystemid[0]['id']

Your @getsystemid is not a Hash, it is an Array of Hash. @getsystemid[0] will give you the intended hash {"id"=>1000010466, "name"=>"cfme038", "last_checkin"=>#}. Now you can use Hash#[] method to access the value of the hash by using its keys.

Why do I get no implicit conversion of String into Integer (TypeError) ?

From the exception, it seems that json in the second response is an array with only one element, so the output of puts json is the same (brackets don't get output with puts), but json["string"] fails because [] expects an Integer to use as index.

Check p json or that json.is_a?(Array) and if it is indeed an array, try with json.first['imdb_id'].

No implicit conversion of string into integer on ruby on rails

The root of the problem is that x isn't a hash. I expect it's an array.

For example this will give you the same error:

[]["symbol"]

Basically, when x is an array, the input of the [] method expects an integer, and therefore tries to convert what is passed in, into an integer. The error occurs when the conversion fails.

TypeError: no implicit conversion of String into Integer in ruby

Looks like you are trying to print the ids of the objects which are in a Array.

Try this: puts "{billing_ids.map(&:id)}"

About the error TypeError: no implicit conversion of String into Integer

The error is because you are tring to access an index "id" of an Array of Billing objects. The id attribute of a particular object can be obtained but if you try accessing id of the Array, thats not going to work. (Note billing_ids is an Array as per your code). Array can be accessed by indices which are integers (unlike Hash)

Why am I getting no implicit conversion of String into Integer when trying to get Nested JSON attribute?

because "provider" is an array.

it should be accessed with index.

[:value][0][:provider][0][:name]

same goes with "value".

TypeError - no implicit conversion of String into Integer

The problem is here:

techcrunch.articles["url"]

techcrunch["articles"] is an array. You might want to iterate through articles:

<% @techcrunch["articles"].each do |techcrunch| %>

and remove .articles:

techcrunch["url"]

from where it failed.

no implicit conversion of nil into String error

One of (or more) values in string

finalStatsFile.puts col_date+", "+col_constant1+", "+ col_appYear+", "+col_statsDesc+", "+col_constant2+", "+col_keyStats+", "+col_weeklyTotal

became nil. To fix the output you should explicitly cast them to strings:

finalStatsFile.puts col_date.to_s + ", " + 
col_constant1.to_s + ", " +
col_appYear.to_s + ", " +
col_statsDesc.to_s + ", " +
col_constant2.to_s + ", " +
col_keyStats.to_s + ", " +
col_weeklyTotal.to_s

BTW, the whole clause might be rewritten in more rubyish manner:

finalStatsFile.puts [ col_date,
col_constant1,
col_appYear,
col_statsDesc,
col_constant2,
col_keyStats,
col_weeklyTotal ].map(&:to_s).join(', ')


Related Topics



Leave a reply



Submit