【发布时间】:2011-12-03 22:00:06
【问题描述】:
尝试浏览 tekpub rack 教程但遇到此错误。
Boot Error
Something went wrong while loading app.ru
LoadError: cannot load such file -- haiku
在与我尝试运行的应用程序相同的目录中有一个名为 haiku.rb 的文件,但在尝试运行程序时出现上述错误。代码如下:
class EnvironmentOutput
def initialize(app=nil)
@app = app
end
def call(env)
out = ""
unless(@app.nil?)
response = @app.call(env)[2]
out+=response
end
env.keys.each {|key| out+="<li>#{key}=#{env[key]}</li>"}
["200",{"Content-Type" => "text/html"},[out]]
end
end
require 'haml'
require 'haiku'
class MyApp
def call(env)
poem = Haiku.new.random
template = File.open("views/index.haml").read
engine = Haml::Engine.new(template)
out = engine.render(Object.new, :poem => poem)
["200",{"Content-Type" => "text/html"}, out]
end
end
use EnvironmentOutput
run MyApp.new
我确定这是一个小错误,因为代码与教程中的代码相同,并且对他有用...
谢谢
【问题讨论】:
-
如果您在 ruby 1.9 上运行,您可能想尝试
require './haiku.rb',或者将当前目录附加到您的加载路径 ($:.append(File.dirname(__FILE__))),然后执行 `require 'haiku'。 -
感谢您修复它。我会在哪里尝试找到该信息。机架文档还是 Ruby 文档?
-
刚刚将我的评论改写为正确答案。它更具描述性。
标签: ruby-on-rails ruby rack