2

Sinatra 很新,但我正在按照本教程设置一个带有一些静态页面的简单博客站点:http: //danneu.com/posts/15-a-simple-blog-with-sinatra-and-active-record -一些有用的工具/

我创建了包含以下内容的 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]

4

2 回答 2

3

你的错误是这样的:

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'

(当你这样做时,.../blog$ bundle installBundler 应该给你一个警告。)

您将进一步遇到的另一个错误:

在无尾礼服中,它说要这样做:

>> p = new_record?

那应该是:

>> p.new_record?
于 2013-08-09T07:18:11.750 回答
0

我对 config.ru 不是很熟悉,但一个可能的问题是您使用require的是相对文件路径。将第一行更改为 -

require_relative "./app"

可能有帮助。

于 2013-08-09T07:12:13.657 回答