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?
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.
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.
You should launch the application with:
rackup config.ru
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With