learningtech
learningtech

Reputation: 33675

hello world sinatra app error

I'm having trouble learning how to use Sinatra. I finally got phusion-passenger installed and working with my apache2 on Ubuntu. I have the following directories and files

/var/www/html
/var/www/html/public
/var/www/html/tmp
/var/www/html/config.ru   # this is a file

The contents of /var/www/html/config.ru is copied from https://www.phusionpassenger.com/documentation/Users%20guide%20Apache.html#_tutorial_example_writing_and_deploying_a_hello_world_rack_application.

When I start up this application, I get hello world, which is great.

So next, I want to build a Sinatra app. I went ahead and created the file

/var/www/html/myapp.rb

With the contents described by http://www.sinatrarb.com/intro.html . I also did a gem install sinatra. I restarted apache. Then I went to http://localhost/ but I still see hello world of my config.ru. So then I overwrote the contents of config.ru with myapp.rb. I restarted apache. But now I get an error message

missing run or map statement (RuntimeError)
  /usr/lib/ruby/vendor_ruby/rack/builder.rb:133:in `to_app'
  config.ru:1:in `<main>'
  /usr/share/passenger/helper-scripts/rack-preloader.rb:112:in `eval'
  /usr/share/passenger/helper-scripts/rack-preloader.rb:112:in `preload_app'
  /usr/share/passenger/helper-scripts/rack-preloader.rb:158:in `<module:App>'
  /usr/share/passenger/helper-scripts/rack-preloader.rb:29:in `<module:PhusionPassenger>'
  /usr/share/passenger/helper-scripts/rack-preloader.rb:28:in `<main>'

What am I doing wrong? How do I build a hello world Sinatra app?

Upvotes: 0

Views: 865

Answers (1)

DiegoSalazar
DiegoSalazar

Reputation: 13521

Your config.ru should require and run your app, like:

require './myapp.rb' 
run Sinatra::Application

And in turn, myapp should require sinatra:

require 'sinatra'

get '/' do
  'Hello world!'
end

Read on about using a config.ru: http://www.sinatrarb.com/intro.html#Using%20a%20Classic%20Style%20Application%20with%20a%20config.ru

Upvotes: 1

Related Questions