在 Sinatra 中使用 Rackup - Cloud9
Using Rackup in Sinatra - Cloud9
我想在 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。
我认为您在 "Hello world"
周围遗漏了几个括号。
来自 blog post 关于机架:
class HelloWorld
def call(env)
[200, {"Content-Type" => "text/plain"}, ["Hello world!"]]
end
end
请注意,"Hello world!"
映射到一个数组中,而 rack 却因在那里找到一个字符串而感到困惑。
我想在 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。
我认为您在 "Hello world"
周围遗漏了几个括号。
来自 blog post 关于机架:
class HelloWorld
def call(env)
[200, {"Content-Type" => "text/plain"}, ["Hello world!"]]
end
end
请注意,"Hello world!"
映射到一个数组中,而 rack 却因在那里找到一个字符串而感到困惑。