Heroku Sinatra应用程序 - 未初始化的恒定Jido

时间:2011-02-17 03:43:49

标签: ruby heroku sinatra require

我有一个小的Sinatra应用程序正在调用我开发的名为Jido的库。这个库由RubyGem提供,我在Sinatra应用程序的Gemfile中列为依赖项。我可以在运行Ruby 1.9.2的本地计算机上运行此应用程序而不会遇到任何错误。但是,当我推送到Heroku并访问使用此“Jido”库的页面时,服务器返回错误。从日志中我看到Heroku服务器正在运行Ruby 1.8.7。这是Heroku错误日志中的堆栈跟踪:

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-a96e-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'

在我的主要Sinatra脚本中与此错误相关的行:

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

正如我所说,这个代码在我的机器上使用Ruby 1.9.2运行良好。我已经测试过从Sinatra应用程序和IRB调用这个Jido模块 - 两者都运行没有问题。我看到当我按照我的Gemfile要求安装jido gem时,我会看到,但由于某些原因我无法在我的Sinatra脚本中引用它...任何想法?

Sinatra应用程序的完整源代码(包括Gemfile和Gemfile.lock)可在https://github.com/hans/jido-site获得。

1 个答案:

答案 0 :(得分:0)

我切换到bamboo-mri-1.9.2堆栈(我之前在bamboo-mri-1.8.7堆栈上)并修复了它。非常感谢TK-421的帮助!