Heroku应用程序无法启动 – “require”:没有要加载的文件 – sinatratestapp(LoadError)

我正在尝试使用bamboo-mri-1.9.2堆栈运行我的Heroku应用程序。 当然它在Ruby 1.9.2上运行良好。 但是在生产时它会在启动时在执行config.ru时崩溃,如下所示:

 require 'sinatratestapp' run Sinatra::Application 

我的.gems文件:

 sinatra --version '>= 1.0' 

而应用程序本身就是sinatratestapp.rb

 require 'rubygems' require 'sinatra' get '/' do "Hello from Sinatra on Heroku!" end 

这就是我在项目中的所有内容,并尝试在Heroku结果上运行:

 :29:in `require': no such file to load -- sinatratestapp (LoadError) from :29:in `require' from config.ru:1:in `block (3 levels) in ' ... -----> Your application is requiring a file that it can't find. Most often this is due to missing gems, or it could be that you failed to commit the file to your repo. See http://docs.heroku.com/gems for more information on managing gems. Examine the backtrace above this message to debug. 

我试图按照它的指导做,但作为一个Ruby noob,我的考试没有任何结果。

在Heroku支持请求和这个问题的帮助下,我找到了解决方案。

Ruby 1.9.2不会自动包含“。” 在$ LOAD_PATH中。 要解决此问题,请通过声明require './sinatratestapp'而不是require './sinatratestapp'来修改config.ru

您可以在config.ru文件中添加以下行,它也将解决问题。 这也将适用于应用范围,因此它将带回1.9.2之前的行为感觉:

$ LOAD_PATH.unshift(Dir.getwd)

注意:我无法在Heroku上进行测试

我的问题:使用没有Gemfile,config.ru或config / unicorn.rb的(ruby <1.9.2)sinatra应用程序让独角兽行为正常。

我相信在尝试使用Sinatra时遇到了这个问题。 默认情况下,Ruby 1.9不包含路径中的当前目录,因此您必须在config.ru文件中隐式声明require 'sinatratestapp'

谢谢你的提示。 在Herokupost中没有提到.gems文件http://blog.heroku.com/archives/2009/3/5/32_deploy_merb_sinatra_or_any_rack_app_to_heroku/

我的Sinatra项目具有相同的布局并且看起来大致相同,唯一的区别是在我的.gems文件中我没有指定版本。

我的.gems看起来像这样:

 sinatra hpricot