【发布时间】:2016-07-27 21:28:54
【问题描述】:
我正在按照本教程在 Sinatra::Base 上找到的食谱进行操作 https://www.safaribooksonline.com/library/view/sinatra-up-and/9781449306847/ch04.html
我在让我的路线工作时遇到问题,目前只有一条路线可以工作,那就是get '/',它从ApplicationController < Sinatra::Base home.erb 加载。
我的第二个控制器中名为 ExampleController < ApplicationController 的路由不起作用
config.ru(仅相关代码)
# Load Controllers and models
Dir.glob('./{controllers,models}/*.rb').each { |file| require file }
map('/example') { run ExampleController }
map('/') { run ApplicationController }
application_controller.rb
class ApplicationController < Sinatra::Base
# set folder for root
set :root, File.expand_path("../app", Dir.pwd)
# don't enable logging when running tests
configure :production, :development do
enable :logging
end
get '/' do
title "Home.erb"
erb :home
end
not_found do
title 'Not Found!'
erb :not_found
end
end
example_controller.rb当前不会加载路由
class ExampleController < ApplicationController
get '/example' do
title "Example Page"
erb :example
end
end
【问题讨论】: