Sinatra options for set_option
Sinatra has several configurable options you can set at the top of your application.
Default options, straight out of the code:
@default_options = { :run => true, :port => 4567, :env => :development, :root => root, :views => root + '/views', :public => root + '/public', :sessions => false, :logging => true, :raise_errors => false }
Key options, and what they do:
- run - Should Sinatra auto-call run on itself with an at_exit handler. The idea is that you don’t have to put in a Sinatra.run anywhere in your application, it just happens automatically. I can’t think of a good reason to turn this off.
- env - Most of the time this is overridden by either the command line or the rackup file. A set in an application’s code will override any other previous setting, but this default isn’t used very often.
- root - Setting this has no effect, since it isn’t ever used anywhere in the code (currently…)
- views - Default views dir
- public - Default public dir (public means static files like css and js)
- sessions - Turn on sessions, uses a cookie store by default. I don’t know how to configure the store.
- logging - enables the Rack::CommonLogger middleware.
One at a time:
# Two arguments, key, then value set :sessions, true set :logging, false
All at once:
# One argument, a hash mapping key -> value set :sessions => true, :logging => false, :views => 'path/to/views' ### For binary options, you can use enable: enable :sessions, :logging
Leave a Reply