未初始化的常量Rack :: Massive(NameError)

时间:2013-01-28 17:37:25

标签: ruby-on-rails ruby rake

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

创建了helloworld.ru

类HelloRack   def call(env)     [“200”,{“Content-Type”=> “text / plain”},“Hello World”]   结束 结束 运行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应用程序教程或有用的链接!!

1 个答案:

答案 0 :(得分:1)

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

require 'rubygems'
require 'rack'

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

use Rack::Massive
run SmallStuff.new