Sinatra Set Settings (Ruby)
Posted
by JP
on Stack Overflow
See other posts from Stack Overflow
or by JP
Published on 2010-04-06T13:29:31Z
Indexed on
2010/04/06
13:33 UTC
Read the original article
Hit count: 227
Using Sinatra in Ruby you can set the server's settings by doing:
set :myvariable, "MyValue"
and then access it anywhere in templates etc with settings.myvariable
.
In my script I need to be able to re-set these variables falling back to a bunch of defaults. I figured the easiest way to do this would be to have a function that performs all the set
s calling it at the start of the Sinatra server and when I need to make the alterations:
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
As explained in the code above, the set_settings
function isn't found, am I going about this the wrong way?
© Stack Overflow or respective owner