2
在Ruby中使用西納特拉您可以通過設置服務器的設置:西納特拉組設定(紅寶石)
set :myvariable, "MyValue"
,然後用settings.myvariable
任何地方訪問它的模板等。
在我的腳本中,我需要能夠重新設置這些變量回落到一堆默認值。我想這樣做,這將是最簡單的方法有執行所有set
■在西納特拉服務器開始調用它,當我需要做出改變的函數:
class MyApp < Sinatra::Application
helpers do
def set_settings
s = settings_from_yaml()
set :myvariable, s['MyVariable'] || "default"
end
end
# Here I would expect to be able to do:
set_settings()
# But the function isn't found!
get '/my_path' do
if things_go_right
set_settings
end
end
# Etc
end
如上代碼解釋上面,set_settings
功能沒有找到,我是這樣錯誤的方式嗎?