如何使用ruby1.9部署机架应用程序?

时间:2011-06-25 18:02:07

标签: ruby heroku sinatra rack

我一直试图在Sinatra上运行一个简单的hello world web应用程序。

我有以下设置:

  • config.ru

    require 'hello.rb'
    run Sinatra::Application
    
  • hello.rb的

    require "sinatra"
    
    get "/" do
        "Hello World!\n"
    end
    
  • 的Gemfile

    source :rubygems
    gem 'sinatra'
    

如果我运行ruby hello.rbruby1.9.1 hello.rbrackup并在浏览器中转到正确的地址,则此功能适用于我的本地计算机。但是,当部署到heroku或运行rackup1.9.1时,这不起作用。我收到以下错误:

<internal:lib/rubygems/custom_require>:29:in `require': no such file to load -- hello.rb (LoadError)
    from <internal:lib/rubygems/custom_require>:29:in `require'
    from config.ru:1:in `block in <main>'
    from /usr/lib/ruby/1.9.1/rack/builder.rb:46:in `instance_eval'
    from /usr/lib/ruby/1.9.1/rack/builder.rb:46:in `initialize'
    from config.ru:1:in `new'
    from config.ru:1:in `<main>'
    from /usr/lib/ruby/1.9.1/rack/builder.rb:35:in `eval'
    from /usr/lib/ruby/1.9.1/rack/builder.rb:35:in `parse_file'
    from /usr/lib/ruby/1.9.1/rack/server.rb:113:in `app'
    from /usr/lib/ruby/1.9.1/rack/server.rb:189:in `wrapped_app'
    from /usr/lib/ruby/1.9.1/rack/server.rb:155:in `start'
    from /usr/lib/ruby/1.9.1/rack/server.rb:83:in `start'
    from /usr/bin/rackup1.9.1:4:in `<main>'

我怎样才能使这个工作?我猜测config.ru应该是不同的,但我不知道该改变什么。

1 个答案:

答案 0 :(得分:1)

尝试

require './hello'

require_relative 'hello'

默认情况下,Ruby 1.9.2中的当前目录不存在于LOAD_PATH中。

相关问题