我正在创建一个Ruby应用程序,当我尝试运行它时,我收到一条错误消息,说它无法加载文件。
在我的主文件app.rb中,我正在尝试要求模型/问题
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
当我使用霰弹枪时,我收到以下错误:
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
这是我的模型/问题文件:
class Issue
include Mongoid::Document
include Mongoid::Timestamps::Updated
field :name, type: String
field :description, type: String
end
答案 0 :(得分:0)
确实
require_relative 'models/issue'
或
require './models/issue'
帮助?