Sample config.ru for various Ruby web frameworks

This guide shows example config.ru files for various Ruby web frameworks.

Table of contents

  • Loading...

Camping

require 'camping'

##### Begin Camping application
Camping.goes :Blog

...your application code here...
##### End Camping application

run Rack::Adapter::Camping.new(Blog)

For Camping versions 2.0 and up, using run Blog as the final line will do.

Grape

In config.ru:

require File.expand_path('my_app', File.dirname(__FILE__))

run MyApp

In my_app.rb:

require 'grape'

class MyApp < Grape::API
  ...
end

Halcyon

require 'halcyon'
$LOAD_PATH.unshift(Halcyon.root / 'lib')
Halcyon::Runner.load_config Halcyon.root/'config'/'config.yml'
run Halcyon::Runner.new

Mack

ENV["MACK_ENV"] ||= ENV["RACK_ENV"]
load("Rakefile")
require 'mack'
run Mack::Utils::Server.build_app

Merb

require 'rubygems'
require 'merb-core'

Merb::Config.setup(
  :merb_root   => ::File.expand_path(::File.dirname(__FILE__)),
  :environment => ENV['RACK_ENV']
)
Merb.environment = Merb::Config[:environment]
Merb.root = Merb::Config[:merb_root]
Merb::BootLoader.run

run Merb::Rack::Application.new

Padrino

require File.expand_path("../config/boot.rb", __FILE__)

run Padrino.application

Rails 2.3

If your application is based on Rails >= 3.0, then you do not need to create a config.ru. Rails >= 3.0 applications already contain a config.ru.

If your application is based on Rails 2.3, then you need to create a config.ru that contains:

require File.expand_path(File.dirname(__FILE__) + '/config/environment')

use Rails::Rack::LogTailer
use Rails::Rack::Static
run ActionController::Dispatcher.new

Ramaze

require "ramaze"
Ramaze.trait[:essentials].delete Ramaze::Adapter
require "start"
Ramaze.start!
run Ramaze::Adapter::Base

Sinatra

In config.ru:

require File.expand_path('my_app', File.dirname(__FILE__))

run MyApp

In my_app.rb:

require 'sinatra/base'

class MyApp < Sinatra::Base
  get "/" do
    "hello world"
  end
end