Skip to content

Instantly share code, notes, and snippets.

@halorgium
Forked from kematzy/app.rb
Created June 2, 2009 03:01
Show Gist options
  • Save halorgium/121956 to your computer and use it in GitHub Desktop.
Save halorgium/121956 to your computer and use it in GitHub Desktop.
# Example of how to use multiple Routes in external files/modules
require 'rubygems'
require 'sinatra/base'
# set the root of the whole app
APP_ROOT = File.dirname(File.expand_path(__FILE__)) unless defined?(APP_ROOT)
require "sinatra-external_routes_example"
class MyApp < Sinatra::Base
set :public, "#{APP_ROOT}/public"
set :views, "#{APP_ROOT}/views"
get '/' do
"hello world"
end
# just dumps the available methods of MyApp, so that you can easily see the routes defined
get '/methods' do
"#{self.methods.sort.join(",\n<br>")}"
end
end #/class MyApp
module MyRoutes
module Blog < Sinatra::Base
get '' do
"hello from blog and foo is [#{options.foo}]"
end
get '/article' do
'hello from blog article'
end
# ....
end #/module Blog
module Gallery < Sinatra::Base
helpers do
# any specific helpers inside here.
end
get '' do
'hello from gallery'
end
get '/one' do
'hello from gallery one'
end
# ....
end #/module Gallery
end #/module MyRoutes
map "/gallery/" do
run MyRoutes::Gallery
end
map "/blog/" do
run MyRoutes::Blog
end
map "/" do
run MyApp
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment