在Sinatra中使用Rackup - Cloud9

时间:2016-05-27 21:06:43

标签: ruby-on-rails sinatra rake cloud9-ide

我想在Cloud9中使用Rack。我创建了一个名为“app.ru”的档案,其代码为:

class HelloWorld

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

end

在终端我放了:

abc:~/workspace $ gem install rack
Successfully installed rack-1.6.4  
1 gem installed

abc:~/workspace $ rackup app.ru -p $PORT -o $IP
[2016-05-27 20:47:15] INFO  WEBrick 1.3.1
[2016-05-27 20:47:15] INFO  ruby 2.3.0 (2015-12-25) [x86_64-linux]
[2016-05-27 20:47:15] INFO  WEBrick::HTTPServer#start: pid=5150 port=8080
190.239.166.29 - - [27/May/2016:20:47:18 +0000] "GET / HTTP/1.1" 200 - 0.0008
[2016-05-27 20:47:18] ERROR NoMethodError: undefined method `each' for #<String:0x00000000a39be8>
 /usr/local/rvm/gems/ruby-2.3.0/gems/rack-1.6.4/lib/rack/body_proxy.rb:31:in `each'
 /usr/local/rvm/gems/ruby-2.3.0/gems/rack-1.6.4/lib/rack/lint.rb:708:in `each'
...

这引发了我的错误here

1 个答案:

答案 0 :(得分:0)

我想你错过了"Hello world"左右的几个括号。

blog post关于Rack:

class HelloWorld
  def call(env)
    [200, {"Content-Type" => "text/plain"}, ["Hello world!"]]
  end
end

请注意,"Hello world!"映射到数组中,并且通过在那里找到字符串来混淆机架。