Domanda

I've included the yajl gem in my Gemfile via gem 'yajl-ruby', '~> 1.1.0' however upon calling parser = Yajl::Parser.new in my store controller I receive the error uninitialized constant StoreController::Yajl

If I execute require 'yajl' at the beginning of the controller all is well but I was under the impression that the gem should be available to controllers within the application simply by including in the gem file.

È stato utile?

Soluzione

You have to indicate to Bundler the main file of the gem with the require option:

gem 'yajl-ruby', '~> 1.1.0', require: 'yajl'

This is necessary for gems whose name is different that their main file name.

See the Gemfile manual.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top