对sinatra来说很新鲜,但是我正在按照这个教程来建立一个带有一些静态页面的简单博客站点:http://danneu.com/posts/15-a-simple-blog-with-sinatra-and-active-record-some-useful-tools/
我创建了包含以下内容的gemfile:

# Gemfile
source :rubygems

gem "sinatra"
gem "sqlite3"
gem "activerecord"
gem "sinatra-activerecord"

group :development do
  gem "shotgun"
  gem "tux"
end

然后使用bundle install安装
我的config.ru如下所示:
#config.ru
require "./app"
run Sinatra::Application

但当我尝试运行tux时,会出现以下错误:
/Users/admin/.rvm/gems/ruby-2.0.0-p195/gems/ripl-rack-0.2.0/lib/ripl/rack.rb:38:in `eval': cannot load such file -- ./app (LoadError)
    from (eval):2:in `block in initialize'
    from /Users/admin/.rvm/gems/ruby-2.0.0-p195/gems/rack-1.5.2/lib/rack/builder.rb:55:in `instance_eval'
    from /Users/admin/.rvm/gems/ruby-2.0.0-p195/gems/rack-1.5.2/lib/rack/builder.rb:55:in `initialize'
    from (eval):1:in `new'
    from (eval):1:in `initialize'
    from /Users/admin/.rvm/gems/ruby-2.0.0-p195/gems/ripl-rack-0.2.0/lib/ripl/rack.rb:38:in `eval'
    from /Users/admin/.rvm/gems/ruby-2.0.0-p195/gems/ripl-rack-0.2.0/lib/ripl/rack.rb:38:in `initialize'
    from /Users/admin/.rvm/gems/ruby-2.0.0-p195/gems/ripl-rack-0.2.0/lib/ripl/rack.rb:18:in `new'
    from /Users/admin/.rvm/gems/ruby-2.0.0-p195/gems/ripl-rack-0.2.0/lib/ripl/rack.rb:18:in `rack'
    from /Users/admin/.rvm/gems/ruby-2.0.0-p195/gems/ripl-rack-0.2.0/lib/ripl/rack.rb:9:in `before_loop'
    from /Users/admin/.rvm/gems/ruby-2.0.0-p195/gems/ripl-multi_line-0.3.1/lib/ripl/multi_line.rb:18:in `before_loop'
    from /Users/admin/.rvm/gems/ruby-2.0.0-p195/gems/ripl-0.7.0/lib/ripl/readline.rb:6:in `before_loop'
    from /Users/admin/.rvm/gems/ruby-2.0.0-p195/gems/ripl-0.7.0/lib/ripl/completion.rb:5:in `before_loop'
    from /Users/admin/.rvm/gems/ruby-2.0.0-p195/gems/ripl-0.7.0/lib/ripl/shell.rb:34:in `loop'
    from /Users/admin/.rvm/gems/ruby-2.0.0-p195/gems/ripl-0.7.0/lib/ripl/runner.rb:49:in `start'
    from /Users/admin/.rvm/gems/ruby-2.0.0-p195/gems/ripl-0.7.0/lib/ripl/runner.rb:31:in `run'
    from /Users/admin/.rvm/gems/ruby-2.0.0-p195/gems/tux-0.3.0/bin/tux:7:in `<top (required)>'
    from /Users/admin/.rvm/gems/ruby-2.0.0-p195/bin/tux:23:in `load'
    from /Users/admin/.rvm/gems/ruby-2.0.0-p195/bin/tux:23:in `<main>'
    from /Users/admin/.rvm/gems/ruby-2.0.0-p195/bin/ruby_noexec_wrapper:14:in `eval'
    from /Users/admin/.rvm/gems/ruby-2.0.0-p195/bin/ruby_noexec_wrapper:14:in `<main>'

你知道是什么引起的吗?我有ruby 2.0.0p195 (2013-05-14 revision 40734) [x86_64-darwin12.4.0]

最佳答案

您的错误是:

cannot load such file -- ./app (LoadError)

这个错误是说tux在当前目录中找不到名为app.rb的文件。Tux正在查找该文件,因为config.ru显示:
config.ru
require "./app"
run Sinatra::Application

看看它是怎么提到一个名为“../app”的文件的?好吧,“教程”不会显示该文件的截图,直到它显示tux的截图。创建app.rb文件,然后运行tux。
同时更改您的gemfile:
source :rubygems

对此:
source 'https://rubygems.org'

(当你这么做的时候,bundler应该给你一个警告。)
您将进一步遇到的另一个错误是:
穿燕尾服,上面写着:
>> p = new_record?

应该是:
>> p.new_record?

关于ruby - 带Sinatra的Tux无法加载,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/18140867/

10-13 04:53