Rails Geocoder says "can't convert string to integer"

Im my index index controller I have @usergeo = Geocoder.search("")

result is:

Geocoder::Result::Freegeoip:0x007ff3ced35eb8 @data={


.class means it is an array!

In the view I try this one:

<%= @usergeo["city"] %>

and the result is

can't convert String into Integer

Also an @usergeo[:city] does not work

any comment will be very helpful to me thanks


Try @usergeo.first.city or @usergeo[0].city as you want to reference the @data sample in this case.

The reason you're getting that error is because you're basically trying to call Array["city"] on the result, but an array obviously expects an integer, not a string. This way you reference the object, which is a hash, and call ["city"] on that instead.

Its no array its a Geocoder::Result::Freegeoip try @usergeo.city instead of @usergeo["city"]

Documentation of this class:


Hope this helps you,...

Need Your Help

download an entire directory in a phoneGap (iOS) from a server?

javascript ios cordova phonegap-plugins cordova-3

i Am struggling for a about 1.5 days trying to find a solution without success.

Questions on the Concepts of Sorting Algorithms

java sorting

I'm currently learning how to program with Java, so I'm taking a class on Data Structures and whatnot. Recently, we've been covering the concepts of Sorting Algorithms, and from the start I've been...