sinatra app doesn't start on run

a 夏天 提交于 2019-12-13 12:38:27

问题


I'm on Ubuntu 10.10/Ruby 1.9.2

Whatever I do, I can't get a sinatra app to start on my local machine.

hello.rb:

require 'sinatra'
get '/' do
  "Hello World!"
end

"$ ruby hello.rb" and "$ ruby -rubygems hello.rb" both result in a new prompt with no action taken.

Any tips or pointers?


回答1:


This is a known issue in Sinatra 1.0 running on Ruby 1.9.2; it has been fixed in Sinatra 1.1 which is just around the corner.

Fix it with enable :run:

require 'sinatra'
enable :run

get '/' do
  "Hello World!"
end

Another issue you might run into with the Ruby 1.9.2 + Sinatra 1.0 stack concerns the change of the default load path for Ruby scripts in Ruby 1.9.2, which doesn't include the current directory, therefore views don't work as expected by default, fix it with:

set :views, File.dirname(FILE) + "/views"



回答2:


Upgrade to Sinatra 1.1.



来源:https://stackoverflow.com/questions/3973402/sinatra-app-doesnt-start-on-run

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!