开发者

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:

  • https://github.com/zapnap/sinatra-template/blob/master/environment.rb; and
  • https://github.com/andrewkolesnikov/sinatra-pro-template/blob/master/environment.rb.

I've tried searching on Google but cannot find 开发者_JS百科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?


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).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜