Undefined `run 'method for main: Object (NoMethodError) Sinatra

require 'sinatra/base' class Foo < Sinatra::Base get('/foo') { 'foo' } end class Bar < Sinatra::Base get('/bar') { 'bar' } end run Rack::Cascade, [Foo, Bar] 

I just can't figure out what is wrong with this code. When I ran: ruby ​​server.rb, it gives an error

+7
source share
1 answer

First of all, the last line should read

 run Rack::Cascade.new [Foo, Bar] 

But you can use this only in the Rackup file. Secondly, you need to create a file called config.ru (Rackup File) with the following contents:

 require './app' run Rack::Cascade.new [Foo, Bar] 

and a file called app.rb with your real application:

 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

 $ 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 the second command prompt window and test the application:

 $ curl 0.0.0.0:9292/foo foo% $ curl 0.0.0.0:9292/bar bar% 
+10
source

All Articles