Last active
August 29, 2015 14:07
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'sinatra' | |
require './app' | |
run Main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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