【问题标题】:Error running Extreme Startup Sinatra web server运行 Extreme Startup Sinatra Web 服务器时出错
【发布时间】:2015-08-27 01:01:42
【问题描述】:

我正在尝试在我的 Windows 机器上设置和运行 Extreme Startup 编码道场。

当我尝试访问 http://localhost:3000 上的首页时,我收到此错误:

application error
Errno::ENOENT at /
No such file or directory @ rb_sysopen - c:/Users/mark/Desktop/extreme_startup/lib/extreme_startup/views/leaderboard.haml
file: template.rb location: initialize line: 210
BACKTRACE
(expand)
JUMP TO: GET POST COOKIES ENV
c:/Users/mark/Desktop/extreme_startup/lib/extreme_startup/web_server.rb in block in <class:WebServer>
    set :players,    Hash.new
    set :players_threads, Hash.new
    set :scoreboard, Scoreboard.new(ENV['LENIENT'])
    set :question_factory, ENV['WARMUP'] ? WarmupQuestionFactory.new : QuestionFactory.new
    set :game_state, GameState.new

    get '/' do
      haml :leaderboard, :locals => {
          :leaderboard => LeaderBoard.new(scoreboard, players, game_state),
          :players => players  }
    end

    get '/scores' do
      LeaderBoard.new(scoreboard, players, game_state).to_json
    end
GET
No GET data.
POST
No POST data.
COOKIES
No cookie data.
Rack ENV
Variable    Value
GATEWAY_INTERFACE   
CGI/1.2
HTTP_ACCEPT 
text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
HTTP_ACCEPT_ENCODING    
gzip, deflate, sdch
HTTP_ACCEPT_LANGUAGE    
en-US,en;q=0.8,en-GB;q=0.6,da;q=0.4
HTTP_CACHE_CONTROL  
max-age=0
HTTP_CONNECTION 
keep-alive
HTTP_HOST   
localhost:3000
HTTP_UPGRADE_INSECURE_REQUESTS  
1
HTTP_USER_AGENT 
Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.157 Safari/537.36
HTTP_VERSION    
HTTP/1.1
PATH_INFO   
/
QUERY_STRING    
REMOTE_ADDR 
127.0.0.1
REQUEST_METHOD  
GET
REQUEST_PATH    
/
REQUEST_URI 
/
SCRIPT_NAME 
SERVER_NAME 
localhost
SERVER_PORT 
3000
SERVER_PROTOCOL 
HTTP/1.1
SERVER_SOFTWARE 
thin 1.6.3 codename Protein Powder
async.callback  
#<Method: Thin::Connection#post_process>
async.close 
#<EventMachine::DefaultDeferrable:0x00000004497b28>
rack.errors 
#<Object:0x000000031c5608>
rack.input  
#<StringIO:0x000000041a6860>
rack.logger 
#<Rack::NullLogger:0x0000000447cd28 @app=#<Rack::Protection::FrameOptions:0x0000000447ce40 @app=#<Rack::Protection::HttpOrigin:0x0000000447cee0 @app=#<Rack::Protection::IPSpoofing:0x0000000447cf80 @app=#<Rack::Protection::JsonCsrf:0x0000000447d020 @app=#<Rack::Protection::PathTraversal:0x0000000447d0c0 @app=#<Rack::Protection::XSSHeader:0x0000000447d1d8 @app=#<ExtremeStartup::WebServer:0x00000004497a88 @default_layout=:layout, @preferred_extension=nil, @app=nil, @template_cache=#<Tilt::Cache:0x00000004497a60 @cache={}>>, @options={:reaction=>:drop_session, :logging=>true, :message=>"Forbidden", :encryptor=>Digest::SHA1, :session_key=>"rack.session", :status=>403, :allow_empty_referrer=>true, :report_key=>"protection.failed", :html_types=>["text/html", "application/xhtml"], :xss_mode=>:block, :nosniff=>true, :except=>[:session_hijacking, :remote_token]}>, @options={:reaction=>:drop_session, :logging=>true, :message=>"Forbidden", :encryptor=>Digest::SHA1, :session_key=>"rack.session", :status=>403, :allow_empty_referrer=>true, :report_key=>"protection.failed", :html_types=>["text/html", "application/xhtml"], :except=>[:session_hijacking, :remote_token]}>, @options={:reaction=>:drop_session, :logging=>true, :message=>"Forbidden", :encryptor=>Digest::SHA1, :session_key=>"rack.session", :status=>403, :allow_empty_referrer=>true, :report_key=>"protection.failed", :html_types=>["text/html", "application/xhtml"], :except=>[:session_hijacking, :remote_token]}>, @options={:reaction=>:drop_session, :logging=>true, :message=>"Forbidden", :encryptor=>Digest::SHA1, :session_key=>"rack.session", :status=>403, :allow_empty_referrer=>true, :report_key=>"protection.failed", :html_types=>["text/html", "application/xhtml"], :except=>[:session_hijacking, :remote_token]}>, @options={:reaction=>:drop_session, :logging=>true, :message=>"Forbidden", :encryptor=>Digest::SHA1, :session_key=>"rack.session", :status=>403, :allow_empty_referrer=>true, :report_key=>"protection.failed", :html_types=>["text/html", "application/xhtml"], :except=>[:session_hijacking, :remote_token]}>, @options={:reaction=>:drop_session, :logging=>true, :message=>"Forbidden", :encryptor=>Digest::SHA1, :session_key=>"rack.session", :status=>403, :allow_empty_referrer=>true, :report_key=>"protection.failed", :html_types=>["text/html", "application/xhtml"], :frame_options=>:sameorigin, :except=>[:session_hijacking, :remote_token]}>>
rack.multiprocess   
false
rack.multithread    
true
rack.request.cookie_hash    
{}
rack.request.query_hash 
{}
rack.request.query_string   
rack.run_once   
false
rack.url_scheme 
http
rack.version    
[1, 0]
sinatra.accept  
[#<Sinatra::Request::AcceptEntry:0x0000000425ace8 @entry="text/html", @type="text/html", @params={}, @q=1.0>, #<Sinatra::Request::AcceptEntry:0x0000000425ab08 @entry="application/xhtml+xml", @type="application/xhtml+xml", @params={}, @q=1.0>, #<Sinatra::Request::AcceptEntry:0x0000000425a5b8 @entry="image/webp", @type="image/webp", @params={}, @q=1.0>, #<Sinatra::Request::AcceptEntry:0x0000000425a928 @entry="application/xml;q=0.9", @type="application/xml", @params={}, @q=0.9>, #<Sinatra::Request::AcceptEntry:0x0000000425a428 @entry="*/*;q=0.8", @type="*/*", @params={}, @q=0.8>]
sinatra.error   
#<Errno::ENOENT: No such file or directory @ rb_sysopen - c:/Users/mark/Desktop/extreme_startup/lib/extreme_startup/views/leaderboard.haml>
sinatra.route   
GET /
You're seeing this error because you have enabled the show_exceptions setting.

据我所知,有问题的代码行在第 28 行,which seems to be this:

haml :leaderboard, :locals => {
    :leaderboard => LeaderBoard.new(scoreboard, players, game_state),
    :players => players  }

不幸的是,我对 Ruby 的了解几乎不存在,所以对我来说没有任何不妥之处。

当我启动 web 服务器时,它会产生这个输出,包括一个警告,我(到目前为止没有成功)试图摆脱它。不知道有没有关系:

$ ruby web_server.rb
:public is no longer used to avoid overloading Module#public, use :public_folder or :public_dir instead
        from c:/Users/mark/Desktop/extreme_startup/lib/extreme_startup/web_server.rb:20:in `<class:WebServer>'
== Sinatra (v1.4.6) has taken the stage on 3000 for development with backup from Thin
Thin web server (v1.6.3 codename Protein Powder)
Maximum connections set to 1024
Listening on localhost:3000, CTRL+C to stop

当我从 Chrome 向http://localhost:3000 发出请求时,控制台会输出以下错误消息:

WARN: tilt autoloading 'tilt/haml' in a non thread-safe way; explicit require 'tilt/haml' suggested.
2015-08-26 15:50:41 - Errno::ENOENT - No such file or directory @ rb_sysopen - c:/Users/mark/Desktop/extreme_startup/lib/extreme_startup/views/leaderboard.haml:
        c:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/tilt-2.0.1/lib/tilt/template.rb:210:in `initialize'
        c:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/tilt-2.0.1/lib/tilt/template.rb:210:in `open'
        c:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/tilt-2.0.1/lib/tilt/template.rb:210:in `read_template_file'
        c:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/tilt-2.0.1/lib/tilt/template.rb:76:in `block in initialize'
        c:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/tilt-2.0.1/lib/tilt/template.rb:77:in `call'
        c:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/tilt-2.0.1/lib/tilt/template.rb:77:in `initialize'
        c:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:861:in `new'
        c:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:861:in `block in compile_template'
        c:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/tilt-2.0.1/lib/tilt.rb:88:in `fetch'
        c:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:840:in `compile_template'
        c:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:821:in `render'
        c:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:676:in `haml'
        c:/Users/mark/Desktop/extreme_startup/lib/extreme_startup/web_server.rb:28:in `block in <class:WebServer>'
        c:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:1610:in `call'
        c:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:1610:in `block in compile!'
        c:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:974:in `[]'
        c:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:974:in `block (3 levels) in route!'
        c:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:993:in `route_eval'
        c:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:974:in `block (2 levels) in route!'
        c:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:1014:in `block in process_route'
        c:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:1012:in `catch'
        c:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:1012:in `process_route'
        c:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:972:in `block in route!'
        c:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:971:in `each'
        c:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:971:in `route!'
        c:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:1084:in `block in dispatch!'
        c:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:1066:in `block in invoke'
        c:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:1066:in `catch'
        c:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:1066:in `invoke'
        c:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:1081:in `dispatch!'
        c:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:906:in `block in call!'
        c:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:1066:in `block in invoke'
        c:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:1066:in `catch'
        c:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:1066:in `invoke'
        c:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:906:in `call!'
        c:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:894:in `call'
        c:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/rack-protection-1.5.3/lib/rack/protection/xss_header.rb:18:in `call'
        c:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/rack-protection-1.5.3/lib/rack/protection/path_traversal.rb:16:in `call'
        c:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/rack-protection-1.5.3/lib/rack/protection/json_csrf.rb:18:in `call'
        c:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/rack-protection-1.5.3/lib/rack/protection/base.rb:49:in `call'
        c:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/rack-protection-1.5.3/lib/rack/protection/base.rb:49:in `call'
        c:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/rack-protection-1.5.3/lib/rack/protection/frame_options.rb:31:in `call'
        c:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/rack-1.6.4/lib/rack/nulllogger.rb:9:in `call'
        c:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/rack-1.6.4/lib/rack/head.rb:13:in `call'
        c:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/sinatra-1.4.6/lib/sinatra/show_exceptions.rb:21:in `call'
        c:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:181:in `call'
        c:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:2021:in `call'
        c:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:1486:in `block in call'
        c:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:1795:in `synchronize'
        c:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:1486:in `call'
        c:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/thin-1.6.3/lib/thin/connection.rb:86:in `block in pre_process'
        c:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/thin-1.6.3/lib/thin/connection.rb:84:in `catch'
        c:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/thin-1.6.3/lib/thin/connection.rb:84:in `pre_process'
        c:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/eventmachine-1.0.8/lib/eventmachine.rb:1062:in `call'
        c:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/eventmachine-1.0.8/lib/eventmachine.rb:1062:in `block in spawn_threadpool'

出了什么问题,我可以做些什么来解决这个问题?

我对 Ruby 几乎一无所知,所以这可能是初学者的愚蠢错误。

【问题讨论】:

  • 我猜你已经检查了c:/Users/mark/Desktop/extreme_startup/lib/extreme_startup/views/leaderboard.haml 存在?
  • @Sirl33tname 事实上,我没有 :$ 我只是 cloned the repository 并且天真地认为一切都会正常工作。正如您可能已经猜到的那样,该文件不存在。我是否需要以某种方式“构建”应用程序才能使该文件(和其他文件)出现?该问题是否与有关:public 的警告有关?
  • 我没有在 windows 上使用 git,但我只是在 linux 上用 git 检查了它,我有那个文件,所以我猜 git checkout 出了点问题。关于公用文件夹设置的警告只是一个警告,我不能 100% 确定它是否会造成问题,但我很确定它与您的问题无关。
  • @Sirl33tname 如果您查看the GitHub web view, you'll see that lib/extreme_startup has no sub-directoriesleaderboard.haml 文件存在于 repo 中,但 in /views。那个文件也在我的硬盘上。该错误消息似乎暗示 Web 服务器正在错误的位置查找视图文件,还是我误解了什么?

标签: ruby windows sinatra


【解决方案1】:

您的问题是该应用程序是很久以前开发的,没有人花时间升级。

例如,您应该使用 ruby​​ 1.9.3 运行它,这已经结束了。 但是使用较新的 ruby​​ 版本可能会起作用。 (至少 ruby​​-2.1.6 对我有用)

但绝对不能用 sinatra v1.4.6 运行这个项目。 正如您在源代码中看到的,这个项目是使用v1.2.6 构建的。 可能您已经为其他项目安装了更新版本的 sinatra。 因此,我建议您将 gems 安装在项目文件夹中:

捆绑安装 --binstubs --path 供应商

如果以这种方式安装,您可以拥有多个具有相同依赖项的项目而不会出现问题。但现在您需要在命令前加上 bundle exec,例如 bundle exec ruby web_server.rb

或者,如果您使用的是 rvm,则有一个名为 gemsets 的东西可以做类似的事情。

【讨论】:

  • 谢谢。该命令的问题在于,如果我发出该命令,我会遇到this problem。有没有办法克服这两个障碍?
  • 你可以用这个pastebin.com/xCBfeTkV 替换你的 Gemfile.lock 并重试吗?
  • 感谢您的努力。它现在通过了 nokogiri 步骤,但在安装 ffi 时失败。这是一个相当大的错误信息,所以我几乎不敢发布它。我想我会在 repo 上发布一个问题,看看原作者是否有兴趣更新代码。非常感谢您的善意努力。
  • 设置 linux VM 可能更容易;D
  • 它可能是,如果有人知道如何做到这一点 - 我不知道:$
猜你喜欢
  • 2016-06-22
  • 1970-01-01
  • 1970-01-01
  • 2012-03-08
  • 1970-01-01
  • 1970-01-01
  • 2014-10-31
  • 2018-07-07
相关资源
最近更新 更多