Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to start a Sinatra app using "run"

Tags:

ruby

sinatra

I tried to use a Gemfile in my Sinatra app, but when I launched my app I got this error:

$ ruby config.ru  
config.ru:7:in `<main>': undefined method `run' for main:Object (NoMethodError)

Here are my three files:

hi.rb:

get "/" do
  "Hello world"
end

Gemfile:

gem "sinatra"

config.ru:

require 'rubygems'
require 'bundler'

Bundler.require

require File.join(File.dirname(__FILE__), 'hi.rb')
run Sinatra::Application

What did I do wrong? How can I fix this?

like image 543
Simon Avatar asked Sep 17 '12 09:09

Simon


People also ask

How do I run config ru?

You can run a basic Rack server with the rackup command which will search for a config.ru file in the current directory. Since Sinatra just like Rails builds on Rack it uses rackup internally to interface between the server and the framework. config.ru is thus the entry point to any Rack based program.

What is a Sinatra app?

Sinatra is a free and open source software web application library and domain-specific language written in Ruby. It is an alternative to other Ruby web application frameworks such as Ruby on Rails, Merb, Nitro, and Camping. It is dependent on the Rack web server interface. It is named after musician Frank Sinatra.


1 Answers

You should launch the application with:

rackup config.ru
like image 194
Riccardo Marotti Avatar answered Nov 16 '22 02:11

Riccardo Marotti