我一直试图在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.rb
,ruby1.9.1 hello.rb
或rackup
并在浏览器中转到正确的地址,则此功能适用于我的本地计算机。但是,当部署到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应该是不同的,但我不知道该改变什么。
答案 0 :(得分:1)
尝试
require './hello'
或
require_relative 'hello'
默认情况下,Ruby 1.9.2中的当前目录不存在于LOAD_PATH中。