Skip to content

Instantly share code, notes, and snippets.

@studio3104
Last active August 29, 2015 14:07
Show Gist options
  • Save studio3104/78e43fb418faea19272b to your computer and use it in GitHub Desktop.
Save studio3104/78e43fb418faea19272b to your computer and use it in GitHub Desktop.
Sinatra で Controller を分割したくなったら Rack::URLMap を使うとよさそう http://studio3104.hatenablog.com/entry/2014/10/03/013500
require 'sinatra/base'
class Main < Sinatra::Base
before do
# nanka
end
get '/' do
'index'
end
get '/foo' do
'foo'
end
get '/bar' do
'bar'
end
end
require 'sinatra'
require './app'
run Main
require 'sinatra/base'
class Base < Sinatra::Base
before do
# nanka
end
end
class Root < Base
get '/' do
'index'
end
end
class Foo < Base
get '/foo' do
'foo'
end
end
class Bar < Base
get '/bar' do
'bar'
end
end
class Main < Sinatra::Base
use Root
use Foo
use Bar
end
require 'sinatra/base'
class Base < Sinatra::Base
before do
# nanka
end
end
class Root < Base
get '/' do
'index'
end
end
class Foo < Base
get '/' do
'foo'
end
end
class Bar < Base
get '/' do
'bar'
end
end
class Main < Sinatra::Base
ROUTES = {
'/' => Root,
'/foo' => Foo,
'/bar' => Bar,
}
end
require 'sinatra'
require './app'
run Rack::URLMap.new(Main::ROUTES)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment