Topic: Ruby 'index ... out of string' error

Topic type:

What to look for when you encounter this mysterious 'index ... out of string' error.

I encountered the following while using the API for the Gmaps4Rails gem:

index 7201 out of string

       Extracted source (around line #38):

37: <script type="text/javascript" charset="utf-8">
38:   <%= raw options.to_gmaps4rails %>
39: </script>
40: <% end %>

The long and the short of it is that you should check that you are passing passing properly formed arguments to the method that you are interacting with in the API.

In my case, I had forgotten to properly embed an array within a hash like so:

[{\"lng\":174.958833333333,\"lat\":-41.1796666666667}] # bad
{"data"=>"[{\"lng\":174.958833333333,\"lat\":-41.1796666666667}]"} # good, note the data key

Judging by what I found by searching the web, others that have encountered the cryptic 'index ... out of string' were also tripped up by passing badly formed stuff to a method in an API.

Discuss This Topic

There are 0 comments in this discussion.

join this discussion

Like what you've read? You can check out my latest project at

Got a project of your own that you need help with? Let's talk