18

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?

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
Simon
  • 619
  • 2
  • 9
  • 23
  • 2
    Use `rackup` command to start your app. Or install shotgun gem, that is more convenient for development. – taro Sep 17 '12 at 10:13

1 Answers1

39

You should launch the application with:

rackup config.ru
Riccardo Marotti
  • 20,218
  • 7
  • 70
  • 53
  • 3
    Can you explain why rackup is necessary or shotgun is necessary? – gustavoanalytics Mar 08 '17 at 21:29
  • 2
    @gustavoanalytics rackup is the script which runs the first and only executable inside a gem called rack using ruby. That executable is also called rackup. Inside it sets up environment for rack applications and starts your default server. – nurettin Jul 29 '18 at 21:33