对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]
答案 0 :(得分: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 install
时,Bundler应该给你一个警告。)
您将进一步遇到的另一个错误:
在tux中,它说要做到这一点:
>> p = new_record?
应该是:
>> p.new_record?
答案 1 :(得分:0)
我对config.ru不是很熟悉,但一个可能的问题是您使用require
作为相对文件路径。将第一行更改为 -
require_relative "./app"
可能有帮助。