Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NoMethodError: undefined method `symbolize_keys!' for Hash

I'm trying to use Hashie outside of Rails. In my rakefile, I've included require hashie/hash, but I still get the NoMethodError. I've tried using require hash; no luck there either.

This is the line it fails on:

YAML.load(ERB.new(File.read('../prefs.yml')).result)['dev'].symbolize_keys!

When I inspect the Hash, it looks correct and takes this form: {'key':'value'}. I want the key to be a symbol, but I don't want to have to switch between Rails 3 and 4, so I installed Hashie and added it to my Rakefile, but that doesn't seem to solve the problem.

Can anyone tell me why I might be getting this error?

like image 736
user3827303 Avatar asked Dec 23 '14 20:12

user3827303


1 Answers

symbolize_keys! method belongs to activesupport(github rubygems) and you can't use this it without this gem.

In order to use it add it to your Gemfile(or via bundle add activesupport) and explicitly require it in your code

require 'active_support/core_ext/hash/keys'

Or you can write use a polyfill like in this gist

https://rubygems.org/gems/activesupport/

like image 86
Philidor Avatar answered Sep 28 '22 15:09

Philidor