在模块化Sinatra应用程序中,config.ru文件中包含以下代码:
# ...
map '/' do
run MyApp::Controller::WelcomesController
run MyApp::Controller::Authenticated::Foo::HomesController
run MyApp::Controller::Authenticated::Foo::SearchesController
end
# ...
Run Code Online (Sandbox Code Playgroud)
以及控制器文件,例如Homes controller:
# app/controllers/authenticated/foo/homes_controller.rb
require_relative 'base'
module MyApp
module Controller
module Authenticated
module Foo
class HomesController < Foo::Base
get '/Users/Foos' do
haml 'authenticated/foo/homes/show'.to_sym
end
end
end
end
end
end
Run Code Online (Sandbox Code Playgroud)
搜索控制器:
# app/controllers/authenticated/foo/searches_controller.rb
require_relative 'base'
module MyApp
module Controller
module Authenticated
module Foo
class SearchesController < Student::Base
get '/Users/Foos/Searches' do
haml 'authenticated/foo/searches/index'.to_sym
end
get '/Users/Foos/Searches/:id' do
haml 'authenticated/foo/searches/show'.to_sym
end
end
end …Run Code Online (Sandbox Code Playgroud)