Skip to content

Instantly share code, notes, and snippets.

@olivierlacan
Last active December 17, 2015 19:29
Show Gist options
  • Save olivierlacan/5661045 to your computer and use it in GitHub Desktop.
Save olivierlacan/5661045 to your computer and use it in GitHub Desktop.
NoMethodError: undefined method `result' for #<TypeError: wrong argument type nil (expected Array)> on Rails 3.2.13 with Ruby 2.0.0p-195 when booting Rails app

If you see this error:

NoMethodError: undefined method `result' for #<TypeError: wrong argument type nil (expected Array)>

It's very likely you have the same issue I encoutered.

Basically, inside ActiveRecord there's a little method called configure_connection which does exactly that. It checks an instance variable called @config for @config[:encoding] and if that's present, it calls:

if @config[:encoding]
  @connection.set_client_encoding(@config[:encoding])
end

That in turns calls PGconn.set_client_encoding which causes an immediate Segmentation Fault (segfault). That's Ruby's way of saying fuck that and tipping over.

I'm not sure what the root cause of this issue is, but since I noted that I was using a rather old version of the PG gem (0.11.0 from 2011) with a rather new version of Ruby, I checked the PG gem's changelog. Sure enough, only version 0.15.0 of the PG gem seems to have been tested with Ruby 2.0.0.

After running bundle update pg my application started properly and the issue appeared to be resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment