【问题标题】:Problems with Sinatra + Mustache in OSX LionOSX Lion 中 Sinatra + Mustache 的问题
【发布时间】:2011-10-24 17:49:16
【问题描述】:

我正在尝试在 OSX Lion 中启动和运行 Sinatra 和 Mustache。经过大量的谷歌搜索后,我没有进一步解决这个问题。我很确定这与 OSX 中的 Ruby 权限有关,因为错误(如下)从示例 config.ru 文件的第一行开始(需要“app”)。项目在这里(https://github.com/defunkt/mustache-sinatra-example

这是我的错误

Boot Error

Something went wrong while loading config.ru

LoadError: no such file to load -- app

/Users/ghostandthemachine/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
/Users/ghostandthemachine/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
config.ru:1:in `block in inner_app'
/Users/ghostandthemachine/.rvm/gems/ruby-1.9.2-p290/gems/rack-1.3.1/lib/rack/builder.rb:51:in `instance_eval'
/Users/ghostandthemachine/.rvm/gems/ruby-1.9.2-p290/gems/rack-1.3.1/lib/rack/builder.rb:51:in `initialize'
config.ru:1:in `new'
config.ru:1:in `inner_app'
/Users/ghostandthemachine/.rvm/gems/ruby-1.9.2-p290/gems/shotgun-0.9/lib/shotgun/loader.rb:112:in `eval'
/Users/ghostandthemachine/.rvm/gems/ruby-1.9.2-p290/gems/shotgun-0.9/lib/shotgun/loader.rb:112:in `inner_app'
/Users/ghostandthemachine/.rvm/gems/ruby-1.9.2-p290/gems/shotgun-0.9/lib/shotgun/loader.rb:102:in `assemble_app'
/Users/ghostandthemachine/.rvm/gems/ruby-1.9.2-p290/gems/shotgun-0.9/lib/shotgun/loader.rb:86:in `proceed_as_child'
/Users/ghostandthemachine/.rvm/gems/ruby-1.9.2-p290/gems/shotgun-0.9/lib/shotgun/loader.rb:31:in `call!'
/Users/ghostandthemachine/.rvm/gems/ruby-1.9.2-p290/gems/shotgun-0.9/lib/shotgun/loader.rb:18:in `call'
/Users/ghostandthemachine/.rvm/gems/ruby-1.9.2-p290/gems/shotgun-0.9/lib/shotgun/favicon.rb:12:in `call'
/Users/ghostandthemachine/.rvm/gems/ruby-1.9.2-p290/gems/rack-1.3.1/lib/rack/builder.rb:134:in `call'
/Users/ghostandthemachine/.rvm/gems/ruby-1.9.2-p290/gems/rack-1.3.1/lib/rack/handler/webrick.rb:59:in `service'
/Users/ghostandthemachine/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/webrick/httpserver.rb:111:in `service'
/Users/ghostandthemachine/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/webrick/httpserver.rb:70:in `run'
/Users/ghostandthemachine/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/webrick/server.rb:183:in `block in start_thread'

任何帮助将不胜感激。提前致谢

【问题讨论】:

    标签: ruby macos sinatra osx-lion mustache


    【解决方案1】:

    在 ruby​​ 1.9.2 中,当前目录不会搜索 required 文件,因此您应该指定路径

    require './app'
    

    同样,在app.rb 中您需要更改

    6require 'views/layout'require './views/layout'

    9:views => 'views',:views => './views',

    【讨论】:

    • 嗯...我已经在 configure.ru 中进行了更改
    • 它对我有用,但我在 app.rb 本身进行了另一次编辑,我不得不将 require 'views/layout' 更改为 require './views/layout'
    • 啊哈,明白了!在清理 rvm 并更新到 1.9.2 之后,确保一切都像你上面所说的那样,我已经启动并运行了。不知道为什么当我之前在 1.9.2 中时它不起作用,但无论如何。再次感谢
    • @JonRose 这很有帮助。感谢您的贡献!
    【解决方案2】:

    换行

    require 'app'
    

    require './app'
    

    看起来您使用的是 Ruby 1.9.2。在这个版本中,当前目录已从 Ruby 的加载路径中删除,因此 require 'app' 不再有效,您需要使用 require './app' 指定文件在当前目录中。我假设示例项目是使用早期版本的 Ruby 构建的。

    【讨论】:

      猜你喜欢
      • 2011-10-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-12
      • 1970-01-01
      • 2012-07-19
      • 2013-09-21
      • 2012-12-26
      相关资源
      最近更新 更多