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
功能没有找到,我是这样错误的方式吗?