Sinatra 引导错误,无法加载此类文件
Sinatra Boot Error, Cannot load such file
我正在创建一个 Ruby 应用程序,当我尝试 运行 它时,我收到一条错误消息,提示它无法加载文件。
在我的主文件 app.rb 中,我试图要求 models/issue
require "models/issue"
class App < Sinatra::Base
enable :sessions
register Sinatra::Flash
get "/" do
"redirect/issues"
end
get "/issues" do
@issues = Issue.all
haml :"issues/index"
end
end
当我使用 shotgun 时,出现以下错误:
Boot Error
Something went wrong while loading config.ru
LoadError: cannot load such file -- models/issue
/Users/kristinerooks/Desktop/issuetracker/lib/app.rb:1:in `require'
/Users/kristinerooks/Desktop/issuetracker/lib/app.rb:1:in `<top (required)>'
config.ru:2:in `require'
config.ru:2:in `block in inner_app'
/Users/kristinerooks/.rvm/gems/ruby-2.2.1/gems/rack-1.6.4/lib/rack/builder.rb:55:in `instance_eval'
/Users/kristinerooks/.rvm/gems/ruby-2.2.1/gems/rack-1.6.4/lib/rack/builder.rb:55:in `initialize'
config.ru:1:in `new'
config.ru:1:in `inner_app'
/Users/kristinerooks/.rvm/gems/ruby-2.2.1/gems/shotgun-0.9.1/lib/shotgun/loader.rb:113:in `eval'
/Users/kristinerooks/.rvm/gems/ruby-2.2.1/gems/shotgun-0.9.1/lib/shotgun/loader.rb:113:in `inner_app'
/Users/kristinerooks/.rvm/gems/ruby-2.2.1/gems/shotgun-0.9.1/lib/shotgun/loader.rb:103:in `assemble_app'
/Users/kristinerooks/.rvm/gems/ruby-2.2.1/gems/shotgun-0.9.1/lib/shotgun/loader.rb:86:in `proceed_as_child'
/Users/kristinerooks/.rvm/gems/ruby-2.2.1/gems/shotgun-0.9.1/lib/shotgun/loader.rb:31:in `call!'
/Users/kristinerooks/.rvm/gems/ruby-2.2.1/gems/shotgun-0.9.1/lib/shotgun/loader.rb:18:in `call'
/Users/kristinerooks/.rvm/gems/ruby-2.2.1/gems/shotgun-0.9.1/lib/shotgun/favicon.rb:12:in `call'
/Users/kristinerooks/.rvm/gems/ruby-2.2.1/gems/shotgun-0.9.1/lib/shotgun/static.rb:14:in `call'
/Users/kristinerooks/.rvm/gems/ruby-2.2.1/gems/rack-1.6.4/lib/rack/urlmap.rb:66:in `block in call'
/Users/kristinerooks/.rvm/gems/ruby-2.2.1/gems/rack-1.6.4/lib/rack/urlmap.rb:50:in `each'
/Users/kristinerooks/.rvm/gems/ruby-2.2.1/gems/rack-1.6.4/lib/rack/urlmap.rb:50:in `call'
/Users/kristinerooks/.rvm/gems/ruby-2.2.1/gems/rack-1.6.4/lib/rack/builder.rb:153:in `call'
/Users/kristinerooks/.rvm/gems/ruby-2.2.1/gems/rack-1.6.4/lib/rack/handler/webrick.rb:88:in `service'
/Users/kristinerooks/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/webrick/httpserver.rb:138:in `service'
/Users/kristinerooks/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/webrick/httpserver.rb:94:in `run'
/Users/kristinerooks/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/webrick/server.rb:294:in `block in start_thread'
我认为文件路径没有问题。我的路径如下所示:
ProjectName
config.ru
lib
app.rb
models
issue.rb
这是我的 config.ru 文件:
require "./env"
require "./lib/app"
run App
这是我的 models/issue 文件:
class Issue
include Mongoid::Document
include Mongoid::Timestamps::Updated
field :name, type: String
field :description, type: String
end
有
require_relative 'models/issue'
或
require './models/issue'
帮助?
我正在创建一个 Ruby 应用程序,当我尝试 运行 它时,我收到一条错误消息,提示它无法加载文件。
在我的主文件 app.rb 中,我试图要求 models/issue
require "models/issue"
class App < Sinatra::Base
enable :sessions
register Sinatra::Flash
get "/" do
"redirect/issues"
end
get "/issues" do
@issues = Issue.all
haml :"issues/index"
end
end
当我使用 shotgun 时,出现以下错误:
Boot Error
Something went wrong while loading config.ru
LoadError: cannot load such file -- models/issue
/Users/kristinerooks/Desktop/issuetracker/lib/app.rb:1:in `require'
/Users/kristinerooks/Desktop/issuetracker/lib/app.rb:1:in `<top (required)>'
config.ru:2:in `require'
config.ru:2:in `block in inner_app'
/Users/kristinerooks/.rvm/gems/ruby-2.2.1/gems/rack-1.6.4/lib/rack/builder.rb:55:in `instance_eval'
/Users/kristinerooks/.rvm/gems/ruby-2.2.1/gems/rack-1.6.4/lib/rack/builder.rb:55:in `initialize'
config.ru:1:in `new'
config.ru:1:in `inner_app'
/Users/kristinerooks/.rvm/gems/ruby-2.2.1/gems/shotgun-0.9.1/lib/shotgun/loader.rb:113:in `eval'
/Users/kristinerooks/.rvm/gems/ruby-2.2.1/gems/shotgun-0.9.1/lib/shotgun/loader.rb:113:in `inner_app'
/Users/kristinerooks/.rvm/gems/ruby-2.2.1/gems/shotgun-0.9.1/lib/shotgun/loader.rb:103:in `assemble_app'
/Users/kristinerooks/.rvm/gems/ruby-2.2.1/gems/shotgun-0.9.1/lib/shotgun/loader.rb:86:in `proceed_as_child'
/Users/kristinerooks/.rvm/gems/ruby-2.2.1/gems/shotgun-0.9.1/lib/shotgun/loader.rb:31:in `call!'
/Users/kristinerooks/.rvm/gems/ruby-2.2.1/gems/shotgun-0.9.1/lib/shotgun/loader.rb:18:in `call'
/Users/kristinerooks/.rvm/gems/ruby-2.2.1/gems/shotgun-0.9.1/lib/shotgun/favicon.rb:12:in `call'
/Users/kristinerooks/.rvm/gems/ruby-2.2.1/gems/shotgun-0.9.1/lib/shotgun/static.rb:14:in `call'
/Users/kristinerooks/.rvm/gems/ruby-2.2.1/gems/rack-1.6.4/lib/rack/urlmap.rb:66:in `block in call'
/Users/kristinerooks/.rvm/gems/ruby-2.2.1/gems/rack-1.6.4/lib/rack/urlmap.rb:50:in `each'
/Users/kristinerooks/.rvm/gems/ruby-2.2.1/gems/rack-1.6.4/lib/rack/urlmap.rb:50:in `call'
/Users/kristinerooks/.rvm/gems/ruby-2.2.1/gems/rack-1.6.4/lib/rack/builder.rb:153:in `call'
/Users/kristinerooks/.rvm/gems/ruby-2.2.1/gems/rack-1.6.4/lib/rack/handler/webrick.rb:88:in `service'
/Users/kristinerooks/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/webrick/httpserver.rb:138:in `service'
/Users/kristinerooks/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/webrick/httpserver.rb:94:in `run'
/Users/kristinerooks/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/webrick/server.rb:294:in `block in start_thread'
我认为文件路径没有问题。我的路径如下所示:
ProjectName
config.ru
lib
app.rb
models
issue.rb
这是我的 config.ru 文件:
require "./env"
require "./lib/app"
run App
这是我的 models/issue 文件:
class Issue
include Mongoid::Document
include Mongoid::Timestamps::Updated
field :name, type: String
field :description, type: String
end
有
require_relative 'models/issue'
或
require './models/issue'
帮助?