質問

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.

役に立ちましたか?

解決

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.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top