aneta_bielska [:blog]

Troubleshooting: undefind method to_h for Array
#heroku #ruby

Quick tip.

When I finished working on next feature I made sure everything works on localhost. Then I pushed to Heroku where my app …failed. I checked heroku logs.

I have found an error which was quite surprising:

NoMethodError - undefined method `to_h' for []:Array:

Why didn’t I get this error on localhost ? I digged for a moment and I found out that the #to_h method for Array is only available in Ruby version 2.1 or higher.

On my machine the default ruby version was 2.1.5. Apparently Heroku used an older version.

The solution was quite obvious.

Adding ruby version to Gemfile solved the problem:

ruby '2.1.5' # or any higher version than 2.1


That’s one of the reasons why to add ruby version to your Gemfile.

You may also enjoy:


#servers (1) #hosting (1) #sinatra (2) #assets (1) #sprockets (1) #react-js (1) #data-mapper (1) #ROM (1) #sequel (1) #ORM (1) #pg (1) #sqlite3 (1) #postgresql (1) #ruby (4) #ubuntu (1) #heroku (1) #git (1) #css (3) #cors (1) #same-origin-policy (1) #rake (1) #web-scraping (1) #ruby-on-rails (1) #brug (1) #elixir (1) #benchmark (1)