Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>There was a similar problem with sinatra 1.0 on ruby 1.9.2. The answer there was to add <code>enable :run</code> to your code.</p> <p>Have a look at the <a href="http://www.sinatrarb.com/configuration.html#__enabledisable_the_builtin_web_server" rel="noreferrer">docs for the <code>:run</code> configuration</a> - if you're going to be deploying to a server you'll want to do something like <code>enable :run if __FILE__ == $0</code> so that you only start the built-in server during development when you need it.</p> <p>Strictly speaking your code is correct and should run okay, and in fact it does with ruby 1.8.7 and 1.9.2. <strike>The problem seems to be running it with ruby 1.9.1. In general 1.9.1 seems to be fairly outdated and you should probably look to upgrade to 1.9.2 if you can. If Ubuntu doesn't have any packages for 1.9.2 take a look at <a href="https://rvm.io" rel="noreferrer">rvm</a>.</strike> (In fact if you're going to be doing ruby development rvm is worth a look anyway).</p> <hr> <h3>Update:</h3> <p>I managed to get ruby 1.9.1 compiled to test this, and your code worked ok. Also a bit of googling suggests that the <a href="http://packages.ubuntu.com/maverick/ruby1.9.1" rel="noreferrer">Ubuntu ruby1.9.1 package provides ruby 1.9.2 anyway</a>. So there seems to be something else going on causing <code>:run</code> not to be set when running the file directly, though I don't know what that could be.</p> <h3>Another update:</h3> <p>Looking at the <a href="http://packages.ubuntu.com/maverick/libsinatra-ruby1.9.1" rel="noreferrer">Ubuntu Sinatra package</a> it looks like it's at version 1.0. It could be that your setup is using the Ubuntu package and ignoring the more recent version installed via rubygems. This could explain what's happening. If so this isn't a "a similar problem" to ruby 1.9 and sinatra 1.0 like I suggested above, it's the same problem!</p> <h3>Yet another update:</h3> <p>A couple of things have occurred to me. You can check what version of Sinatra you're actually using with something like <code>puts Sinatra::VERSION</code> after <code>require 'sinatra'</code>. Also, it looks like <a href="http://packages.ubuntu.com/maverick/i386/ruby1.9.1/filelist" rel="noreferrer">there is a <code>gem1.9.1</code> command</a> that corresponds to <code>ruby1.9.1</code>. It looks like when you installed sinatra with <code>sudo gem install sinatra</code> the latest version got installed into the ruby 1.8 install, and left ruby 1.9 with the Ubuntu packaged Sinatra 1.0. If you haven't switched over to rvm yet, you could try <code>sudo gem1.9.1 install sinatra</code>.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload