开发者

Heroku Sinatra app — unitialized constant Jido

I have a small Sinatra application that is calling a library I developed named Jido. This library is provided by a RubyGem that I list as a dependency in the Sinatra app's Gemfile. I can run this application without experiencing any errors on my local machine, which is running Ruby 1.9.2. When I push to Heroku and visit the page that makes use of this "Jido" library, however, the server returns an error. From the logs I see that the Heroku server is running Ruby 1.8.7. Here is the stack trace in the Heroku error log:

2011-02-16T18:42:29-08:00 app[web.1]: NameError - uninitialized constant Jido:
2011-02-16T18:42:29-08:00 app[web.1]:  ./jido.rb:23:in `GET /conjugate/:lang/:verb'
2011-02-16T18:42:29-08:00 app[web.1]:  /app/9d9320fd-f5b9-4dca-a96e-0bdee91997b0/home/.bundle/gems/ruby/1.8/gems/sinatra-1.1.2/lib/sinatra/base.rb:1057:in `call'
2011-02-16T18:42:29-08:00 app[web.1]:  /app/9d9320fd-f5b9-4dca-a96e-0bdee91997b0/home/.bundle/gems/ruby/1.8/gems/sinatra-1.1.2/lib/sinatra/base.rb:1057:in `compile!'
2011-02-16T18:42:29-08:00 heroku[router]: GET jido.heroku.com/conjugate/en/be dyno=web.1 queue=0 wait=1029ms service=5ms bytes=228
2011-02-16T18:42:29-08:00 app[web.1]:  /app/9d9320fd-f5b9-4dca-a96e-0bdee91997b0/home/.bundle/gems/ruby/1.8/gems/sinatra-1.1.2/lib/sinatra/base.rb:643:in `instance_eval'
2011-02-16T18:42:29-08:00 app[web.1]:  /app/9d9320fd-f5b9-4dca-a96e-0bdee91997b0/home/.bundle/gems/ruby/1.8/gems/sinatra-1.1.2/lib/sinatra/base.rb:643:in `route_eval'
2011-02-16T18:42:29-08:00 app[web.1]:  /app/9d9320fd-f5b9-4dca-a96e-0bdee91997b0/home/.bundle/gems/ruby/1.8/gems/sinatra-1.1.2/lib/sinatra/base.rb:627:in `route!'
2011-02-16T18:42:29-08:00 app[web.1]:  /app/9d9320fd-f5b9-4dca-a96e-0bdee91997b0/home/.bundle/gems/ruby/1.8/gems/sinatra-1.1.2/lib/sinatra/base.rb:675:in `process_route'
2011-02-16T18:42:29-08:00 app[web.1]:  /app/9d9320fd-f5b9-4dca-a96e-0bdee91997b0/home/.bundle/gems/ruby/1.8/gems/sinatra-1.1.2/lib/sinatra/base.rb:672:in `catch'
2011-02-16T18:42:29-08:00 app[web.1]:  /app/9d9320fd-f5b9-4dca-a96e-0bdee91997b0/home/.bundle/gems/ruby/1.8/gems/sinatra-1.1.2/lib/sinatra/base.rb:672:in `process_route'
2011-02-16T18:42:29-08:00 app[web.1]:  /app/9d9320fd-f5b9-4dca-a96e-0bdee91997b0/home/.bundle/gems/ruby/1.8/gems/sinatra-1.1.2/lib/sinatra/base.rb:626:in `route!'
2011-02-16T18:42:29-08:00 app[web.1]:  /app/9d9320fd-f5b9-4dca-a96e-0bdee91997b0/home/.bundle/gems/ruby/1.8/gems/sinatra-1.1.2/lib/sinatra/base.rb:625:in `each'
2011-02-16T18:42:29-08:00 app[web.1]:  /app/9d9320fd-f5b9-4dca-a96e-0bdee91997b0/home/.bundle/gems/ruby/1.8/gems/sinatra-1.1.2/lib/sinatra/base.rb:625:in `route!'
2011-02-16T18:42:29-08:00 app[web.1]:  /app/9d9320fd-f5b9-4dca-a96e-0bdee91997b0/home/.bundle/gems/ruby/1.8/gems/sinatra-1.1.2/lib/sinatra/base.rb:760:in `dispatch!'
2011-02-16T18:42:29-08:00 app[web.1]:  /app/9d9320fd-f5b9-4dca-a96e-0bdee91997b0/home/.bundle/gems/ruby/1.8/gems/sinatra-1.1.2/lib/sinatra/base.rb:553:in `call!'
2011-02-16T18:42:29-08:00 app[web.1]:  /app/9d9320fd-f5b9-4dca-a96e-0bdee91997b0/home/.bundle/gems/ruby/1.8/gems/sinatra-1.1.2/lib/sinatra/base.rb:725:in `instance_eval'
2011-02-16T18:42:29-08:00 app[web.1]:  /app/9d9320fd-f5b9-4dca-a96e-0bdee91997b0/home/.bundle/gems/ruby/1.8/gems/sinatra-1.1.2/lib/sinatra/base.rb:725:in `invoke'
2011-02-16T18:42:29-08:00 app[web.1]:  /app/9d9320fd-f5b9-4dca-a96e-0bdee91997b0/home/.bundle/gems/ruby/1.8/gems/sinatra-1.1.2/lib/sinatra/base.rb:725:in `catch'
2011-02-16T18:42:29-08:00 app[web.1]:  /app/9d9320fd-f5b9-4dca-a96e-0bdee91997b0/home/.bundle/gems/ruby/1.8/gems/sinatra-1.1.2/lib/sinatra/base.rb:725:in `invoke'
2011-02-16T18:42:29-08:00 app[web.1]:  /app/9d9320fd-f5b9-4dca-a96e-0bdee91997b0/home/.bundle/gems/ruby/1.8/gems/sinatra-1.1.2/lib/sinatra/base.rb:553:in `call!'
2011-02-16T18:42:29-08:00 app[web.1]:  /app/9d9320fd-f5b9-4dca-a96e-0bdee91997b0/home/.bundle/gems/ruby/1.8/gems/sinatra-1.1.2/lib/sinatra/base.rb:538:in `call'
2011-02-16T18:42:29-08:00 app[web.1]:  /app/9d9320fd-f5b9-4dca-a96e-0bdee91997b0/home/.bundle/gems/ruby/1.8/gems/rack-1.2.1/lib/rack/methodoverride.rb:24:in `call'
2011-02-16T18:42:29-08:00 app[web.1]:  /app/9d9320fd-f5b9-4dca-a96开发者_运维技巧e-0bdee91997b0/home/.bundle/gems/ruby/1.8/gems/rack-1.2.1/lib/rack/commonlogger.rb:18:in `call'
2011-02-16T18:42:29-08:00 app[web.1]:  /app/9d9320fd-f5b9-4dca-a96e-0bdee91997b0/home/.bundle/gems/ruby/1.8/gems/sinatra-1.1.2/lib/sinatra/base.rb:1167:in `call'
2011-02-16T18:42:29-08:00 app[web.1]:  /app/9d9320fd-f5b9-4dca-a96e-0bdee91997b0/home/.bundle/gems/ruby/1.8/gems/sinatra-1.1.2/lib/sinatra/base.rb:1193:in `synchronize'
2011-02-16T18:42:29-08:00 app[web.1]:  /app/9d9320fd-f5b9-4dca-a96e-0bdee91997b0/home/.bundle/gems/ruby/1.8/gems/sinatra-1.1.2/lib/sinatra/base.rb:1167:in `call'
2011-02-16T18:42:29-08:00 app[web.1]:  /home/heroku_rack/lib/static_assets.rb:9:in `call'
2011-02-16T18:42:29-08:00 app[web.1]:  /home/heroku_rack/lib/last_access.rb:15:in `call'
2011-02-16T18:42:29-08:00 app[web.1]:  /app/9d9320fd-f5b9-4dca-a96e-0bdee91997b0/home/.bundle/gems/ruby/1.8/gems/rack-1.2.1/lib/rack/urlmap.rb:47:in `call'
2011-02-16T18:42:29-08:00 app[web.1]:  /app/9d9320fd-f5b9-4dca-a96e-0bdee91997b0/home/.bundle/gems/ruby/1.8/gems/rack-1.2.1/lib/rack/urlmap.rb:41:in `each'
2011-02-16T18:42:29-08:00 app[web.1]:  /app/9d9320fd-f5b9-4dca-a96e-0bdee91997b0/home/.bundle/gems/ruby/1.8/gems/rack-1.2.1/lib/rack/urlmap.rb:41:in `call'
2011-02-16T18:42:29-08:00 app[web.1]:  /home/heroku_rack/lib/date_header.rb:14:in `call'
2011-02-16T18:42:29-08:00 app[web.1]:  /app/9d9320fd-f5b9-4dca-a96e-0bdee91997b0/home/.bundle/gems/ruby/1.8/gems/rack-1.2.1/lib/rack/builder.rb:77:in `call'
2011-02-16T18:42:29-08:00 app[web.1]:  /usr/ruby1.8.7/lib/ruby/gems/1.8/gems/thin-1.2.6/lib/thin/connection.rb:76:in `pre_process'
2011-02-16T18:42:29-08:00 app[web.1]:  /usr/ruby1.8.7/lib/ruby/gems/1.8/gems/thin-1.2.6/lib/thin/connection.rb:74:in `catch'
2011-02-16T18:42:29-08:00 app[web.1]:  /usr/ruby1.8.7/lib/ruby/gems/1.8/gems/thin-1.2.6/lib/thin/connection.rb:74:in `pre_process'
2011-02-16T18:42:29-08:00 app[web.1]:  /usr/ruby1.8.7/lib/ruby/gems/1.8/gems/thin-1.2.6/lib/thin/connection.rb:57:in `process'
2011-02-16T18:42:29-08:00 app[web.1]:  /usr/ruby1.8.7/lib/ruby/gems/1.8/gems/thin-1.2.6/lib/thin/connection.rb:42:in `receive_data'
2011-02-16T18:42:29-08:00 app[web.1]:  /usr/ruby1.8.7/lib/ruby/gems/1.8/gems/eventmachine-0.12.10/lib/eventmachine.rb:256:in `run_machine'
2011-02-16T18:42:29-08:00 app[web.1]:  /usr/ruby1.8.7/lib/ruby/gems/1.8/gems/eventmachine-0.12.10/lib/eventmachine.rb:256:in `run'
2011-02-16T18:42:29-08:00 app[web.1]:  /usr/ruby1.8.7/lib/ruby/gems/1.8/gems/thin-1.2.6/lib/thin/backends/base.rb:57:in `start'
2011-02-16T18:42:29-08:00 app[web.1]:  /usr/ruby1.8.7/lib/ruby/gems/1.8/gems/thin-1.2.6/lib/thin/server.rb:156:in `start'
2011-02-16T18:42:29-08:00 app[web.1]:  /usr/ruby1.8.7/lib/ruby/gems/1.8/gems/thin-1.2.6/lib/thin/controllers/controller.rb:80:in `start'
2011-02-16T18:42:29-08:00 app[web.1]:  /usr/ruby1.8.7/lib/ruby/gems/1.8/gems/thin-1.2.6/lib/thin/runner.rb:143:in `run!'
2011-02-16T18:42:29-08:00 app[web.1]:  /usr/ruby1.8.7/lib/ruby/gems/1.8/gems/thin-1.2.6/bin/thin:6
2011-02-16T18:42:29-08:00 app[web.1]:  /usr/ruby1.8.7/bin/thin:19:in `load'

The lines relevant to this error, in my main Sinatra script:

require 'rubygems'
require 'sinatra'

require 'json'
require 'jido'

conjugators = {}
get '/conjugate/:lang/:verb' do
    content_type :json

    conjugator = nil
    if conjugators[params[:lang]].nil?
    conjugator = Jido.load params[:lang] # exception "Uninitialized constant Jido" is thrown here
    conjugators[params[:lang]] = conjugator
    else conjugator = conjugators[params[:lang]] end

    conjugator.conjugate(params[:verb]).to_json
end

As I said, this code runs fine on my machine with Ruby 1.9.2. I have tested calling this Jido module from both the Sinatra app as well as from IRB — both run without problems. I see when I push to Heroku that the jido gem is installed as required by my Gemfile, but for some reason I can not reference it in my Sinatra script.. any ideas?

The full source for the Sinatra app (including the Gemfile and Gemfile.lock) is available at https://github.com/hans/jido-site .


I switched to the bamboo-mri-1.9.2 stack (I was previously on the bamboo-mri-1.8.7 stack) and that fixed it. Thanks so much for the help TK-421!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜