本文介绍了main:Object(NoMethodError)Sinatra的未定义方法`run'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
require 'sinatra/base'
class Foo < Sinatra::Base
get('/foo') { 'foo' }
end
class Bar < Sinatra::Base
get('/bar') { 'bar' }
end
run Rack::Cascade, [Foo, Bar]
我只是无法猜出这段代码有什么问题.当我运行:ruby server.rb时,它抛出一个错误
I just can't guess what is wrong with this code.When I ran: ruby server.rb, it throws an error
推荐答案
首先,最后一行应读
run Rack::Cascade.new [Foo, Bar]
但是您只能在Rackup文件中使用它.因此,第二步,您需要创建一个名为config.ru的文件(Rackup File),其内容如下:
But you can only use this in a Rackup File. So second, you need to create a File called config.ru (Rackup File) with the following contents:
require './app'
run Rack::Cascade.new [Foo, Bar]
和一个名为app.rb的文件,其中包含您的实际应用程序:
and a file called app.rb with your actual app:
require 'sinatra/base'
class Foo < Sinatra::Base
get('/foo') { 'foo' }
end
class Bar < Sinatra::Base
get('/bar') { 'bar' }
end
然后您可以通过在命令行中键入启动服务器
then you can start the server by typing in the command line
$ rackup
>> Thin web server (v1.3.1 codename Triple Espresso)
>> Maximum connections set to 1024
>> Listening on 0.0.0.0:9292, CTRL+C to stop
之后,打开第二个命令行窗口并测试您的应用程序:
after that, open a second command line window and test your app:
$ curl 0.0.0.0:9292/foo
foo%
$ curl 0.0.0.0:9292/bar
bar%
这篇关于main:Object(NoMethodError)Sinatra的未定义方法`run'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!