我很難學習如何使用Sinatra。我終於安裝了phusion-passenger,並在Ubuntu上使用我的apache2。我有以下的目錄和文件hello world sinatra app error
/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複製。
當我啓動這個應用程序,我得到你好世界,這是偉大的。
接下來,我想構建一個Sinatra應用程序。我繼續創建文件
/var/www/html/myapp.rb
與http://www.sinatrarb.com/intro.html描述的內容。我也做了一個gem install sinatra
。我重新啓動了Apache。然後我去了http://localhost/
,但我仍然看到我的config.ru
的hello world
。於是我用myapp.rb
重寫了config.ru
的內容。我重新啓動了Apache。但現在我收到一條錯誤消息
missing run or map statement (RuntimeError)
/usr/lib/ruby/vendor_ruby/rack/builder.rb:133:in `to_app'
config.ru:1:in `<main>'
/usr/share/passenger/helper-scripts/rack-preloader.rb:112:in `eval'
/usr/share/passenger/helper-scripts/rack-preloader.rb:112:in `preload_app'
/usr/share/passenger/helper-scripts/rack-preloader.rb:158:in `<module:App>'
/usr/share/passenger/helper-scripts/rack-preloader.rb:29:in `<module:PhusionPassenger>'
/usr/share/passenger/helper-scripts/rack-preloader.rb:28:in `<main>'
我在做什麼錯?我如何構建一個Hello World世界的Sinatra應用程序?
我建議先學習並測試Sinatra的獨立模式。一旦你對此感到滿意,然後將其連接到Passenger。嘗試使用Passenger最初只會讓你需要理解的內容變得更多,並且使得更難確定哪些內容會在堆棧中發揮作用。就其本身而言,Sinatra非常易於使用,並且不需要其他任何東西來處理HTTP請求。這是一個相當有能力的小型網絡服務器DSL,特別是在與Haml和Thin配合使用時。 Sinatra的主頁顯示瞭如何創建一個「hello world」應用程序,它只需要三行代碼就可以完成。 – 2014-10-16 17:10:06