你好世界sinatra应用程序错误

时间:2014-10-16 15:56:39

标签: ruby sinatra

我在学习如何使用Sinatra方面遇到了麻烦。我终于安装了phusion-passenger并在Ubuntu上使用我的apache2。我有以下目录和文件

/var/www/html
/var/www/html/public
/var/www/html/tmp
/var/www/html/config.ru   # this is a file

/var/www/html/config.ru的内容已从https://www.phusionpassenger.com/documentation/Users%20guide%20Apache.html#_tutorial_example_writing_and_deploying_a_hello_world_rack_application复制。

当我启动这个应用程序时,我得到了hello world,这很棒。

接下来,我想构建一个Sinatra应用程序。我继续创建文件

/var/www/html/myapp.rb

使用http://www.sinatrarb.com/intro.html描述的内容。我也做了gem install sinatra。我重新启动了apache。然后我去了http://localhost/,但我仍然看到hello world的{​​{1}}。然后我用config.ru覆盖了config.ru的内容。我重新启动了apache。但现在我收到一条错误消息

myapp.rb

我做错了什么?我如何构建一个hello world Sinatra应用程序?

1 个答案:

答案 0 :(得分:1)

您的config.ru应该要求并运行您的应用,例如:

require './myapp.rb' 
run Sinatra::Application

反过来,myapp应该要求sinatra:

require 'sinatra'

get '/' do
  'Hello world!'
end

继续阅读使用config.ru:http://www.sinatrarb.com/intro.html#Using%20a%20Classic%20Style%20Application%20with%20a%20config.ru