pyrmont
pyrmont

Reputation: 231

Sinatra and environment.rb

I'm developing a Sinatra-based application and have seen some apps using an environment.rb file in the root of the app with code placed within a configure block. See examples at:

I've tried searching on Google but cannot find an explanation of how the environment.rb file works with Sinatra and why you would put something in a configure block.

Anyone able to shed some light or direct me to where I should do some more research?

Upvotes: 4

Views: 5032

Answers (1)

Paul Hoffer
Paul Hoffer

Reputation: 12906

The purpose of the configure block is to set various Sinatra environment all in one place, and different settings for dev vs production. The configure method itself is a part of the Sinatra framework.

This page explains Sinatra environment variables, if you haven't seen it yet. As for putting it in a separate file, it just helps to break an app into separate files. Some people prefer to break Sinatra apps into many files, whereas smaller apps can actually just be one large file.

A good example of the former is Phrogz' answer to this question (which also includes an example of using configure, albeit in the application file rather than in a separate configuration file).

Upvotes: 4

Related Questions