1
在Website
裏面,我可以獲得root爲settings.root
。在課堂之外,我看不到如何獲得類對象的句柄。我可以訪問網站應用程序類以外的Sintra設置嗎?
我可以在路由塊內插入一個實例變量@root = settings.root
,這將使根可用HAML。這是正確的方式嗎?
class Website < Sinatra::Base
configure do
set :root, File.dirname(__FILE__)
end
get '/' do
haml :index, :layout => :base
end
末
非常好!我可以通過'locals [:root_path]'來訪問它 – Todd 2013-03-06 16:26:51