`sinatra/json` fails with `NameError` #103

leafduo opened this Issue Apr 19, 2013 · 3 comments


None yet
4 participants

leafduo commented Apr 19, 2013

I'm using sinatra-contrib 1.4.0, and #json method doesn't work properly, it throws this:

NameError - uninitialized constant MultiJson:
        /Users/leafduo/.rvm/gems/ruby-2.0.0-p0/gems/sinatra-contrib-1.4.0/lib/sinatra/json.rb:125:in `block in <module:Sinatra>'
        /Users/leafduo/.rvm/gems/ruby-2.0.0-p0/gems/sinatra-contrib-1.4.0/lib/sinatra/json.rb:109:in `resolve_encoder'
        /Users/leafduo/.rvm/gems/ruby-2.0.0-p0/gems/sinatra-contrib-1.4.0/lib/sinatra/json.rb:99:in `json'
        api.rb:6:in `block in <main>'

The document mentioned that I can replace a encoder, so I did that and wasted a long time...

As in ff66f80, sinatra/json started using multi_json, and dropped the ability to choose encoder, we should do require 'multi_json' in our code (rather than user's code) and clean up outdated document and code (like #resolve_encoder_action).

maoueh commented May 8, 2013

I can confirm this also.

Added dependencies to my gemspec:

  gem.add_dependency "json", "~> 1.7.7"
  gem.add_dependency "multi_json", "~> 1.7.3"

And added a required clause into my application. Thanks @leafduo for the workaround.


kgrz commented Jun 13, 2013



zzak commented Aug 16, 2013

Fixed by #96

zzak closed this Aug 16, 2013

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