Craig Smitham
Craig Smitham

Reputation: 3965

sinatra app doesn't start on run

I'm on Ubuntu 10.10/Ruby 1.9.2

Whatever I do, I can't get a sinatra app to start on my local machine.

hello.rb:

require 'sinatra'
get '/' do
  "Hello World!"
end

"$ ruby hello.rb" and "$ ruby -rubygems hello.rb" both result in a new prompt with no action taken.

Any tips or pointers?

Upvotes: 2

Views: 1263

Answers (2)

Konstantin Haase
Konstantin Haase

Reputation: 25944

Upgrade to Sinatra 1.1.

Upvotes: 5

Sirupsen
Sirupsen

Reputation: 2115

This is a known issue in Sinatra 1.0 running on Ruby 1.9.2; it has been fixed in Sinatra 1.1 which is just around the corner.

Fix it with enable :run:

require 'sinatra'
enable :run

get '/' do
  "Hello World!"
end

Another issue you might run into with the Ruby 1.9.2 + Sinatra 1.0 stack concerns the change of the default load path for Ruby scripts in Ruby 1.9.2, which doesn't include the current directory, therefore views don't work as expected by default, fix it with:

set :views, File.dirname(FILE) + "/views"

Upvotes: 10

Related Questions