2

我正在尝试首先在我使用代码创建 helloworld.ru 的目录中创建一个 rake 基本应用程序

class HelloRack def call(env) ["200",{"Content-Type" => "text/plain"}, "Hello World"] end end run HelloRack.new

我用 rackup helloworld.ru 运行它,之后我用代码在同一目录中创建了三个文件 Massive.rb

module Rack
  class Massive
    def initialize(app)
      @app = app
    end

    def call(env)
      status, headers, response= @app.call(env)
      [status, headers, "<div style="font-size:5.0em">#{response} - it's all small stuff</div>"]
    end
  end
end

其他文件名为 SmallStuff.rb

class SmallStuff
  def call(env)
    ["200", {"Content-Type" => "text/html"}, "Don't Sweat The Small Stuff"]
  end
end

还有一个文件名为 config.ru 和代码

require 'rubygems'
require 'rack'

use Rack::Massive
run SmallStuff.new

当我运行 rackup config.ru 它给了我错误

/home/ritesh/rails/config.ru:4: uninitialized constant Rack::Massive (NameError)
    from /var/lib/gems/1.8/gems/rack-1.4.4/lib/rack/builder.rb:51:in `instance_eval'
    from /var/lib/gems/1.8/gems/rack-1.4.4/lib/rack/builder.rb:51:in `initialize'
    from /home/ritesh/rails/config.ru:0:in `new'
    from /home/ritesh/rails/config.ru:0

如何删除此错误我是 rake 应用程序的新手,任何人都可以提供 rake 应用程序教程或有用的链接!

4

1 回答 1

1

看起来您只是缺少一两个requires。首先将您的其他文件重命名为 mass.rb 和 small_stuff.rb(以遵循 Ruby 约定),然后像这样要求它们:

require 'rubygems'
require 'rack'

require_relative './massive'
require_relative './small_stuff'

use Rack::Massive
run SmallStuff.new
于 2013-01-28T17:50:55.077 回答