尝试完成tekpub架子教程,但遇到以下错误。
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
我相信这只是一个小错误,因为代码与教程中的代码相同,并且它对他起作用...
谢谢
require './haiku.rb'
,或将当前目录附加到您的加载路径 ($:.append(File.dirname(__FILE__))
),然后执行require 'haiku'
。 - Frost